PDA

View Full Version : [SOLVED] Find and replace in a file Unix Scripting



hakermania
May 6th, 2010, 05:59 PM
I have a file with the current path. I read the current path with 'pwd'. However this has a disadvantage: If a directory has spaces (e.g. /home/alex/Home Sweet Home) the pwd will output "/home/alex/Home Sweet Home" and no "/home/alex/Home\ Sweet\ Home". So, I want in the file to replace each space with backsplash-space ( i mean each " " with "\ " without the quotes)

Thx in advance for any replies!

tgm4883
May 6th, 2010, 06:22 PM
You could pipe it to sed to replace the space

pwd | sed 's/ /\\ /g'

hakermania
May 6th, 2010, 07:49 PM
Ok thank you this worked.