[Sussex] Sed One Liner
John Patrick
nhoj.patrick at gmail.com
Sat Aug 16 15:59:58 UTC 2008
Afternoon,
I've been trying to alter a sed one liner so it automatically picks up the
current directory, instead of having to manually enter path information.
I hope the following is understandable.
1 $ pwd
/demo_dir
2 $ cat TEST
resources.file=/demo_dir/sub_dir/resources.properties
3 $ sed 's/\/demo_dir/ROOT_DIR/g' TEST > TEST
4 $ cat TEST
resources.file=ROOT_DIR/subdir/resources.properties
5 $ sed 's/ROOT_DIR/\/demo_dir/g' TEST > TEST
6 $ cat TEST
resources.file= /demo_dir/subdir/resources.properties
I basically I run a version of what is show on line 3 prior to checking into
source control and line 5 when I get the latest from source control. At the
moment I can't get sed to correctly pick up an enviroment variable PWD or
dynamically use the output of the pwd command.
As far as I'm aware the following should do what I require but it won't work
and the only example online I can find is changing the line endings,
basically doing dos2unix in sed.
>From what I've found out online the 2 lines bwloe should do what I require
but I just can't get them working.
$ sed "s/`pwd`/ROOT_DIR/g" TEST > TEST
$ sed "s/$PWD/ROOT_DIR/g" TEST > TEST
I've been trying things in my spare time for about a week now but just can't
get any variation of using any of the following characters to work. ` ' " /
\
Cheers for any assistance,
John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/sussex/attachments/20080816/9dd9b842/attachment.htm
More information about the Sussex
mailing list