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!

Sed question

Status
Not open for further replies.

danhodges99

IS-IT--Management
Feb 6, 2003
21
GB
Hi,

I need to place a line of text into a file at a certain point, and I have been using:

sed '
/theWord/ {
atheNewLine
}' < sourceFile > newFile

This works a treat, trouble is that it adds theNewLine underneath EVERY occurrence of lines containing theWord. Does anyone know a way to simply add theNewLine underr the FIRST occurence of theWord, or indeed how to group multiple words together as theWord and add theNewLine under that?

Hope this is clear, thanks :)
 
thread822-489830

awk 'output == 1{print &quot;Output Text&quot;; output=2} /line4/ && output<1 {output=1} {print}' <file>

should work
 
the a and i command need a empty line at the end
give 2 newlines at end of the 'theNewLine' string
you do not need the '<' redirect, sed is able to open files.

sed '
/theWord/ {
atheNewLine

}' sourceFile > newFile

this sure works in a sed-cmd-file, my be also on cmd-line

sed '
/theWord/atheNewLine

' sourceFile > newFile



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top