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

Help with SED oneliner

Status
Not open for further replies.

dbadmin

Programmer
Jan 3, 2003
147
US
Hi Gurus,

I have a text file and need to print the lines before a regular expression and then delete them. I have the following sed oneliner which prints the lines after the regular expression. Please help me in modifying the same to achive the above.

cat test.lst | sed -n '/regexp/,$p'

Thank You!
dbadmin
 
Hi

UUOC
Code:
[gray]# after[/gray]
sed -n '/regexp/,$p' test.lst

[gray]# before ( ugly )[/gray]
sed -n '1,/regexp/p' test.lst

[gray]# before ( optimized, as we learned from PHV )[/gray]
sed '/regexp/q' test.lst

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top