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

oneliner - insert line in file after regexpres

Status
Not open for further replies.

simpson

MIS
Oct 23, 2001
58
CA
I am looking to insert a line of text in a file after a specific line. I know how to do it based on the line number:
#perl -pi -le 'print "New line Insertion" if $. == 100' file.txt

How would i adjust the example above for inserting "New Line Insertion" on the line after my search pattern?

Any help with this would be greatly appreciated.
Mike
 
Use -n instead of -p (i.e. disable AutoPrintTM), and do the printing yourself.

Code:
#perl -ni -le 'print; print "New line Insertion" if /regex/' file.txt

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top