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

Apending word before each line in a file.

Status
Not open for further replies.

ranjank

IS-IT--Management
May 9, 2003
176
0
0
IN
Hi,

I have a file which continas 300 lines with each line starting with ".
e.g

"/var/opt/log"

I want to append a word before each line like :--

%dir %attr(0755,root,root)"/var/opt/log"

Can anyone give pointers on this.

--Ranjan.
 
With sed you may use ^ as a regular expression for the beginning of the line.

So to add the word 'newtext' at the beginning of every line:
sed -e 's/^/newtext/' input_file

Or to replace the word 'oldtext' by 'newtext', but only if it is at the beginning of a line:
sed -e 's/^oldtext/newtext/' input_file

hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top