Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grep or Awk or Sed ? Please Help

Status
Not open for further replies.

hg4372

Technical User
Feb 9, 2009
43
US
I'm fairly new to unix so please bear with me.

I have several log files that I need to extract certain lines from and output to another file.

I apologize for the crude example:

Bob
Jim
Joe
Ralph
Steve
George

I only want to extract Lines 3 through 5 and pipe to a file.

Could someone please give me some direction. I didn't think that Grep would work, however after reading the man pages for awk and sed, I'm not sure where to start.

Please help.
 
sed -n '3,5p' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Or, if you chose to use awk:

Code:
awk 'NR>=3 && NR<=5' /path/to/input

If the files are very large you may want to make it exit when it reaches the final line for efficiency:

Code:
awk 'NR>=3 { print } NR==5 { exit }' /path/to/input

or 

sed -n '3,5p;5q' /path/to/input


Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top