Quote:
Originally Posted by MMKD
I am having trouble creating a perl file that will search for a string in a file and then copy the next few lines (not always the same number of lines) and write to a file.
The log file looks like this:
[... deleted ...]
And what i want to do is search for
Code:
AttributeSyncCallback
when found copy up to the next line that has the same string
Code:
AttributeSyncCallback
in it and write to file.
|
Do you want to copy it up to line #4 (which the next occurrence), or up to line #18 (which is the end of the error block)?
Quote:
You can see in this example that the work AttributeSyncCallback occurs only twice and are the same length, this is a coincidence and will not always be the same.
Can anyone help?
|
The words occur 6 times on 4 lines: 1, 4, 18, and 21. If you want to grab the entire error block, try something like this:
perl -ne 'print if / ERROR \[your-string\] / ... / ERROR \[/'
However, this won't grab the 2nd block if the same error string occurs in consecutive blocks, as it did in your input sample. For this, you'll need a more complicated script.
.