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

Multiple sed commands.......... 1

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to perform the following on the output of a command ::--->

Remove the top 5 lines..........
Remove the bottom 2 lines....
Reverse line order

I created the following sed file ::--->

1,5d
N;$!P;$!D;$d
1!G;h;$!d

command | sed -e cleanup.sed

Doesn't seem to work....

Any ideas?

Thanks....

Joe Despres
 
What about this ?
command | awk '{x[NR]=$0}END{for(i=NR-2;i>5;--i)print x}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That worked!

I ran a awk command prior to my sed....

awk '{print $1, $4, $5}'

can this be included?

Thanks...

Joe Despres
 
Like this ?
command | awk '{x[NR]=$1" "$4" "$5}END{for(i=NR-2;i>5;--i)print x}'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
jdespres:

I prefer the awk solution, but sed is possible:

sed -e '6,$!d' -e 'N;$!P;$!D;$d' mydata.txt|sed '1!G;h;$!d'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top