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

Delete 1 line (only) that matches a pattern using sed

Status
Not open for further replies.

cardy

Technical User
Sep 5, 2000
33
GB
If this is easier than I think I'll kick myself.

I know that I can delete all lines that match a pattern with

sed -e '/<pattern>/d' input > output

But how do I delete the line containing the n'th occurrence of the pattern only.

Thanks

cardy
 
cardy, you may try awk (example for 5th pattern):
awk '/pattern/{++n}{if(n==5)++n;else print}' input > output


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top