Find a string; print next line

December 26, 2006 at 20:28:03
Specs: UNIX Solaris, fast/gobs
I have an output file from a CAD program. In it, I have CG and MOI data. When I see a string that tells me, "CG about CSY origin:", I want to capture the very next line -- the XYZ data. For other similar tasks, the info has been all on one line and I can just grep for the string and send it to a file.

IS there a way I can find string and printthe very next line? Note, this string (and the need to capture line+1) occurs "n" time through out this file with 100,000 or so lines.


See More: Find a string; print next line

Report •

December 27, 2006 at 22:31:47
GNU sed gives you the ability of grep'ing for lines before and after a match. Since you're running Solaris, you probably don't have it. You can probably download it at

If you don't want to do that, try these links:

They might be able to help you out.

Report •

January 1, 2007 at 18:14:54
Thanks Nails.

Here's the approach I took; see if you can add more sanity to my hacking:
Since the first target line always ends with "frame:" (and it's the second target line I want to capture), I'm keying off that "frame" string, appending the next to the first, then I "awk" the appropriate columns to get the XYZ data that was on the "second" line (now appended to the "first")


sed -e :a -e '/frame\:$/N; s/frame\:n/ /; ta' filelist > xyzappend

awk '{print $8"\t"$9"\t"$10}' xyzappend > xyzonly
I appreciate your help; the links you sent were helpful.
Thank you for the response,


Report •

Related Solutions

Ask Question