s0ylgr3n
Technical User
- Feb 19, 2009
- 4
I have a file of test data where I need to match on a pattern and then back up x number of lines (it varies) to match on the date/time stamp and then I need to continue to go forward in the text block until I match on the first blank line or in this case a hex pattern of
0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A.
What I have so far is:
awk '{a[NR]=$0}/pattern/{print a[NR-15]}' /path/to/input
This matches on the pattern and backs up to the date/time stamp and outputs it to std out.
But the lines between the match and backing up to the date/time stamp are always a different number of lines.
I think what I need is a variation of this command:
awk '/match_on_test_data/,/match_on_hex_pattern_at_end_text_block/' /path/to/input
awk '{a[NR]=$0}/match_on_test_data/{print a[NR-15]}' /path/to/input
but I need to make the above "[NR-15]" into a loop that loops up until it matches on the date/time stamp. I searched for a loop structure that might work but so far have not been successful.
File structure is sort of like this:
Sat Jan 31 01:56:15 2009(abcd .... wxyz)test_has_passed(abcd .... wxyz)
&
Sat Jan 31 01:57:41 2009(abcd .... wxyz)test_has_passed(abcd .... wxyz)
&
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(abcd .... wxyz)
(abcd .... wxyz)
Sat Jan 31 01:58:24 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
wq15 HAS FAILED "i want to match on wq15"
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A.
&
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(abcd .... wxyz)
Fri Jan 30 09:53:26 2009
(abcd .... wxyz)
(abcd .... wxyz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed (abcd .... wxyz)
(abcd .... wxyz)
wq15 there's another wq15 to match at the bottom
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed (abcd .... wxyz)
(abcd .... wxyz)
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
(abcd .... wxyz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed (abcd .... wxyz)
(abcd .... wxyz)
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
wq15
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Any help is appreciated ... my remaining hair thanks you.
0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A.
What I have so far is:
awk '{a[NR]=$0}/pattern/{print a[NR-15]}' /path/to/input
This matches on the pattern and backs up to the date/time stamp and outputs it to std out.
But the lines between the match and backing up to the date/time stamp are always a different number of lines.
I think what I need is a variation of this command:
awk '/match_on_test_data/,/match_on_hex_pattern_at_end_text_block/' /path/to/input
awk '{a[NR]=$0}/match_on_test_data/{print a[NR-15]}' /path/to/input
but I need to make the above "[NR-15]" into a loop that loops up until it matches on the date/time stamp. I searched for a loop structure that might work but so far have not been successful.
File structure is sort of like this:
Sat Jan 31 01:56:15 2009(abcd .... wxyz)test_has_passed(abcd .... wxyz)
&
Sat Jan 31 01:57:41 2009(abcd .... wxyz)test_has_passed(abcd .... wxyz)
&
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(abcd .... wxyz)
(abcd .... wxyz)
Sat Jan 31 01:58:24 2009
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
wq15 HAS FAILED "i want to match on wq15"
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
(abcd .... wxyz)
0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A 0D 0A.
&
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(abcd .... wxyz)
Fri Jan 30 09:53:26 2009
(abcd .... wxyz)
(abcd .... wxyz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed (abcd .... wxyz)
(abcd .... wxyz)
wq15 there's another wq15 to match at the bottom
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed (abcd .... wxyz)
(abcd .... wxyz)
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
(abcd .... wxyz)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed (abcd .... wxyz)
(abcd .... wxyz)
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
two letters_and_two numbers
wq15
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Any help is appreciated ... my remaining hair thanks you.