Mar 20, 2007 #1 ranjank IS-IT--Management May 9, 2003 176 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.
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.
Mar 20, 2007 #2 hoinz MIS Jan 29, 2004 944 DE 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 Upvote 0 Downvote
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