1

I have a large text file that I need to add text at the beginning of each line.

This is the text I need to add:

http://test.mysite.com/

I believe that I can use command line similar to this:

sed 's/^/Text Here/' file.txt  > new-file.txt

The problem is that I have slashes in the text I'm adding so I don't know if that's messing it up or if there's a better way to do it...

User
  • 21
  • 3
  • possible duplicate of [How to replace strings containing slashes with sed?](http://stackoverflow.com/questions/16790793/how-to-replace-strings-containing-slashes-with-sed) – that other guy Aug 06 '14 at 19:43

2 Answers2

1

You can use alternate regex delimiter in sed with -i (inline editing) flag:

sed -i.bak 's~^~http://test.mysite.com/~' file.txt
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

well there is a way but i think is very slow:

while read line;do
echo "http://test.mysite.com/"${line} >> new-file-2.txt;
done < new-file.txt

Very slow i think.

About slashes on bash, maybe you should scape it with something like:

sed 's/^/http:\/\/test.mysite.com\//' file.txt > new-file.txt