GREP LIST OF STRINGs

Apple Macbook notebook
March 2, 2010 at 12:50:17
Specs: Macintosh , 500
Hi,

I have a list of strings that are in a file and I need to find in another file and print out that string and the corresponding lines below. I am trying to use grep except that the number of lines below the grepped string vary. However each string is represented by a > so it possible to grep a string and print the line where the string is located and all the lines until you reach >

Any insight would be great
Thanks,

Pete


See More: GREP LIST OF STRINGs

Report •

#1
March 3, 2010 at 01:40:26
Grep only searches lines, you can't make grep print the next line - AWK would work better for that.

Or - sometimes, it's easier to just remove the line breaks completely & use extended grep to match what you're looking for, i.e. something like:

cat file.txt | tr -d "\n" | egrep -o '>[^>]*>'

But...you're destroying the lines here - so you can't find the original line number w/ this method.

If that doesn't work, use AWK or PERL


Report •
Related Solutions


Ask Question