search and replace string with backslash


I have a file which contains relative paths like so:

# source.txt

what id like to do is replace the ./ with the base dir like so:

# result.txt

source.txt has some 15 million entries and Id like to replace all the ./ at the start to have the base dir like the above.

Python would be too slow for this .replace("./","/home/foo..") and I am looking for a sed or grep solution.

>Solution :

Like this

$ sed "s@^\./@$/base/dir/@" file
# source.txt

To replace in-line:

sed -i "s@^\./@/base/dir/@" file

Leave a ReplyCancel reply