LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   SED @ explanation (https://www.linuxquestions.org/questions/programming-9/sed-%40-explanation-641601/)

wood 05-12-2008 04:55 AM

SED @ explanation
 
I have come across this statement when I am learning the tutorial from this website http://www.magiclinux.org/node/895

#gcc -dumpspecs | sed 's@/lib/ld-linux.so.2@/tools&@g' \
> `dirname $(gcc -print-libgcc-file-name)`/specs

What is the s@/lib/ld-linux.so.2@/tools&@g stands for?
I know that if s/color/colour/g means change all color to colour.
But there is an @ in the statement?

Thank you.

druuna 05-12-2008 05:04 AM

Hi,

The seperator that is normally used (the /) can be anything you like in sed.

s/xxxx/yyyy/g is the same as s@xxxx@yyyy@g

This way you do not need to escape the slashes in the pathname (/lib/ld-linux instead of \/lib\/ld-linux).

Hope this clears things up a bit.

pwc101 05-12-2008 05:07 AM

You can use any delimiter you want in a sed expression; it will use whatever follows the s (in this instance) as the delimiter. So, the following are synonymous:
Code:

sed 's@/lib/ld-linux.so.2@/tools&@g'
sed 's_/lib/ld-linux.so.2_/tools&_g'
sed 's£/lib/ld-linux.so.2£/tools&£g'

They used an @ here because using / would have resulted in a mess:
Code:

sed 's/\/lib\/ld-linux.so.2/\/tools&/g'
edit: Too slow by far! ;)

wood 05-13-2008 06:41 AM

Thanks so much for the explanation. Now I am totally clear of it.


All times are GMT -5. The time now is 08:48 AM.