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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract certain lines from an output. 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi everyone,

I understand that you can use

Code:
cat something.txt | sed -ne '1p'

cat something.txt | sed -ne '2,4p'

to either extract one or several lines from an Output.

However ...

How can it be accomplished to extract several specific lines from an Output ?
Let's say I want only lines 2,5 and 8 ...

Regards,
Thomas
 
What about this ?
sed -ne '2p;5p;8p'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

Or try to formulate a rule, for your above example, each 3[sup]rd[/sup] between the 2[sup]nd[/sup] and 8[sup]th[/sup] :
Code:
sed -ne '2,8{2~3p}'
Of course, not a big deal in this case, however if the rule would say each 3[sup]rd[/sup] between 2[sup]nd[/sup] and 800[sup]th[/sup], enumeration would become abit painful.

Feherke.
feherke.ga
 
Feherke, the first~step syntax is valid only with GNU sed, not legacy sed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top