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

Removing arbitrary text from a file

Status
Not open for further replies.

jouell

MIS
Nov 19, 2002
304
US
Hi.

I would like to remove arbritary text from a file, ideally acting on one file in place.

IE

this file:

2+12345+/bin/cat /etc/passwd | /bin/grep -i bash
3+14445+/bin/cat /etc/svc.conf | /bin/grep -i telnet
4+17376+/bin/cat /etc/hosts | /bin/grep -i server


becomes

2+12345+/bin/cat /etc/passwd | /bin/grep -i bash
4+17376+/bin/cat /etc/hosts | /bin/grep -i server


by removing the middle line (but I can't assume an order to the lines or that they will be incremental)

Any ideas?

I really like to act on the one file in place. I can do this in sed with 2 files easily, and I can't figure out how to do it in ed. I am open to awk or anything else that can act on the file in place. I am using Linux, BTW...

Thanks!
-john




 
something like this?

ed file <<eof_ed
/grep -i telnet$/ d
w
q
eof_ed

/search criteria/ d delete line with first occurence of your search criteria
w writes the file back, less your deleted file
q leaves ed command

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top