Operating System - HP-UX
1827859 Members
1796 Online
109969 Solutions
New Discussion

Using a simple SED script

 
SOLVED
Go to solution
Lee nino
New Member

Using a simple SED script

Hi,

I have a file containing names of file I wish to link to a working directory.

I wish to insert ln ./path/path2/ in front of every line of text, and then execute the file to link the files in the list to my working directory.

How do I use a / in the field?

I have tried the following without succes:

sed "s/^/ln ./path1/path2//" file.tmp > file.lnk

Thanks for your help.

5 REPLIES 5
Jean-Luc Oudart
Honored Contributor

Re: Using a simple SED script

You have to pretect slash with a backslash

example
echo abc | sed -e 's/^/\/tmp\//'
/tmp/abc

Rgds,
Jean-Luc
fiat lux
Brian Bergstrand
Honored Contributor

Re: Using a simple SED script

You need to escape the / character with a backslash (\).

So all /'s will look like "\/".

HTH.
curt larson_1
Honored Contributor

Re: Using a simple SED script

unlike addresses, which require a slash (/)
as a delimiter, the regular experession can be delimited by any character except a blank or a newline. thus if the pattern contained slashes, you could choose another character, such as an exclamation mark as the delimiter

sed 's!^!ln ./p1/p2/!'
Umapathy S
Honored Contributor
Solution

Re: Using a simple SED script

Lee,
Open vi and execute the below

:%s:^:\./path/path2/:

You can try the same in sed also. Use a different seperator or escape with a backslash \ before the /.

Try this one
sed -e "s:^:ln \./path1/path2/:" file.tmp >file.lnk

HTH,
Umapathy

Arise Awake and Stop NOT till the goal is Reached!
John Meissner
Esteemed Contributor

Re: Using a simple SED script

to put a "/" (slash) in your sed script you will need to escape it due to it being a special character. to escape any character you can use a "\" (back slash) so you would use it like so:

cat file | sed 's/^/^\/path1\/path2\//g' > links.txt

cat links.txt |
while read line
do
ln -s $line .
done
All paths lead to destiny