how i can add Add text at the beginning of each line?

for example:- i have file contain:- /var/lib/svn/repos/b1me/products/payone/generic/code/core /var/lib/svn/repos/b1me/products/payone/generic/code/fees /var/lib/svn/repos/b1me/products/payone/generic/code/2ds

i want it to become:-

svn+ssh://svn.xxx.com.jo/var/lib/svn/repos/b1me/products/payone/generic/code/core svn+ssh://svn.xxx.com.jo/var/lib/svn/repos/b1me/products/payone/generic/code/fees svn+ssh://svn.xxx.com.jo/var/lib/svn/repos/b1me/products/payone/generic/code/2ds

in other word i want to add "svn+ssh://svn.xxx.com.jo" at the beginning of each line of this file

  • to get this to work you are going to have to add an svn command to the beginning of each line too e.g. svn list svn+ssh://svn.xx.com.jo/var ... – Iain Sep 22 '10 at 9:57

If your text is a file named "file.txt" you use this command line

awk '{print "svn+ssh://svn.xxx.com.jo" $1}' file.txt

It will output what you want. (assuming that no path contain a space)


You can use Vim in Ex mode:

ex -sc '%s,^,svn+ssh://svn.xxx.com.jo,|x' filename
  1. % select all lines

  2. s substitute

  3. x save and close


Using sed:

sed 's|^|svn+ssh://svn.xxx.com.jo|' filename

To change the file in place:

sed -i 's|^|svn+ssh://svn.xxx.com.jo|' filename
  • i execute it but the following error apear.....command garbled: – Mohammad AL-Rawabdeh Sep 22 '10 at 7:31
  • Your version of sed may need -e: sed -e 's|^|svn+ssh://svn.xxx.com.jo|' filename – Dennis Williamson Sep 22 '10 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.