iam new to shell scripting and i have plz can anyone help in changing the pattrern "/" to "\" using the sed command.
olympie@gmail.com wrote: > iam new to shell scripting and i have plz can anyone help in changing > the pattrern "/" to "\" using the sed command. sed 's/\//\\/g' will replace all '/' with '\' srp -- http://saju.net.in
Saju Pillai <saju.pillai@gmail.com> wrote: >> iam new to shell scripting and i have plz can anyone help in changing >> the pattrern "/" to "\" using the sed command. > sed 's/\//\\/g' will replace all '/' with '\' For less confusing viewing: sed 's,/,\\,g' For original poster: backslash is "quoting" character so if you need literal, you need it quoted by itself; previous poster had to also quote forward slash because it was used as delimiter in sed commands. p. -- Beware of he who would deny you access to information, for in his heart he dreams himself your master. -- Commissioner Pravin Lal
2009-01-27, 23:07(-08), olympie@gmail.com: > iam new to shell scripting and i have plz can anyone help in changing > the pattrern "/" to "\" using the sed command. Why sed? tr / '\\' -- St�phane
According to Saju Pillai <saju.pillai@gmail.com>: :olympie@gmail.com wrote: :> iam new to shell scripting and i have plz can anyone help in changing :> the pattrern "/" to "\" using the sed command. : :sed 's/\//\\/g' will replace all '/' with '\' : :srp :-- :http://saju.net.in or sed 's#/#\#g' richk
Stephane CHAZELAS wrote: > 2009-01-27, 23:07(-08), olympie@gmail.com: >> iam new to shell scripting and i have plz can anyone help in changing >> the pattrern "/" to "\" using the sed command. > > Why sed? > > tr / '\\' > or simply turn your monitor 90 degrees to the left :-/ I found that shells treat \ in '' differently. Some need '\' and some '\\': Safer is: tr / \\ -- echo imhcea\.lophc.tcs.hmo | sed 's2\(....\)\(.\{5\}\)2\2\122;s1\(.\)\(.\)1\2\11g;1s;\.;::;2'
2009-01-29, 19:50(+01), Michael Tosch: > Stephane CHAZELAS wrote: >> 2009-01-27, 23:07(-08), olympie@gmail.com: >>> iam new to shell scripting and i have plz can anyone help in changing >>> the pattrern "/" to "\" using the sed command. >> >> Why sed? >> >> tr / '\\' >> > > or simply turn your monitor 90 degrees to the left :-/ > > I found that shells treat \ in '' differently. > Some need '\' and some '\\': > > Safer is: > > tr / \\ [...] No, there's no ambiguity here, you want: tr / '\\' whatever the shell (Bourne, rc or csh families). Or in Bourne and csh families tr / \\\\ Or in Bourn family: tr / "\\\\" Or in csh family: tr / "\\" tr's behavior for: tr / '\' (or tr / \\) is unspecified, you need to double the \ for tr. See SUSv4: http://www.opengroup.org/onlinepubs/9699919799/utilities/tr.html for details. -- St�phane
richk@panix.com (Richard T. Kus) wrote: > sed 's#/#\#g' $ echo /usr/bin/sh | sed 's#/#\#g' sed: -e expression #1, char 7: unterminated `s' command If I were to use sed, I would use a double backslash. Peter -- ~/.signature: No such file or directory
Stephane CHAZELAS wrote: > 2009-01-29, 19:50(+01), Michael Tosch: >> Stephane CHAZELAS wrote: >>> 2009-01-27, 23:07(-08), olympie@gmail.com: >>>> iam new to shell scripting and i have plz can anyone help in changing >>>> the pattrern "/" to "\" using the sed command. >>> Why sed? >>> >>> tr / '\\' >>> >> or simply turn your monitor 90 degrees to the left :-/ >> >> I found that shells treat \ in '' differently. >> Some need '\' and some '\\': >> >> Safer is: >> >> tr / \\ > [...] > > No, there's no ambiguity here, you want: > > tr / '\\' > > whatever the shell (Bourne, rc or csh families). > > Or in Bourne and csh families > tr / \\\\ > > Or in Bourn family: > > tr / "\\\\" > > Or in csh family: > > tr / "\\" > > tr's behavior for: > tr / '\' > (or tr / \\) > is unspecified, you need to double the \ for tr. > You are right, tr wants \\, I didn't even check that :-( And what confused me: bash in Solaris: echo '\\' \\ ksh and /bin/sh in Solaris: echo '\\' \ Now I see it's not the shell but the echo command that makes the difference. printf "%s\n" '\\' behaves equally. -- echo imhcea\.lophc.tcs.hmo | sed 's2\(....\)\(.\{5\}\)2\2\122;s1\(.\)\(.\)1\2\11g;1s;\.;::;2'
Michael Tosch <eedmit@NO.eed.SPAM.ericsson.PLS.se> wrote: > And what confused me: > > bash in Solaris: > echo '\\' > \\ > > ksh and /bin/sh in Solaris: > echo '\\' > \ > > Now I see it's not the shell but the echo command > that makes the difference. It depends on whether 'echo' is /usr/bin/echo or /usr/ucb/echo. I don't remember which does what, but one of them converts backslashed characters, like printf '%b' $* whereas the other is like printf '%s' $* Both are described in the manual page for 'echo'. > printf "%s\n" '\\' > > behaves equally. Really? I tried both bash's printf and Solaris' /usr/bin/printf at work today, and in both cases did printf '%s\n' '\\' give \\ Peter -- ~/.signature: No such file or directory