![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sort command - strange behaviour | miwinter | UNIX for Advanced & Expert Users | 16 | 05-29-2008 04:19 AM |
| Longer commands and strange behaviour on ksh | anurags | UNIX for Dummies Questions & Answers | 2 | 03-27-2008 08:04 AM |
| A Strange Behaviour!!! | navojit dutta | Shell Programming and Scripting | 5 | 12-21-2007 01:35 AM |
| /etc/passwd strange behaviour! | penguin-friend | Linux | 0 | 06-06-2005 09:00 AM |
| very strange behaviour on unix server | bolo77 | UNIX for Dummies Questions & Answers | 7 | 03-02-2005 12:32 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Strange sed behaviour
Code:
[/tmp]$ echo a.bc | sed -e "s/\|/\\|/g" |a|.|b|c| [/tmp]$ OS details Code:
Linux 2.6.9-55.0.0.0.2.ELsmp #1 SMP Wed May 2 14:59:56 PDT 2007 i686 i686 i386 GNU/Linux |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
The problem is perhaps in the quotation you use: The shell is probably "eating" your escape chars away and sed doesn't see what you expect it to see.
I made it a habit to use always single quotes for sed-statements to avoid this. It is even possible to use single quotes when using a variable inside an sed-statement: sed 's/'"$src"'/'"$tgt"'/g' will change ocurrences of $src to the value of $tgt I hope this helps. bakunin |
|
#3
|
||||
|
||||
|
Fine. The single quotes vs double quotes has an impact.
Code:
[/tmp]$ echo a.bc | sed -e "s/\|/\\|/g" |a|.|b|c| [/tmp]$ echo a.bc | sed -e 's/\|/\\|/g' \|a\|.\|b\|c\| [/tmp]$ Am I missing something something here ? |
|
#4
|
|||
|
|||
|
To be honest, now i'm astonished myself:
lacking a UNIX machine (got a day off) i fired up cygwin and tried: Code:
# echo a.bc | sed --posix 's/\|/x/g' xax.xbxcx # echo 'a.bc' | sed --posix 's/\|/x/g' xax.xbxcx # echo 'a.bc' | sed --posix 's/|/x/g' a.bc # sed --version GNU sed version 4.1.5 Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, to the extent permitted by law. bakunin |
|
#5
|
|||
|
|||
|
my guess:
\| is used in sed (gnu) as alternation. therefore Code:
# echo "a.bc" | sed -e 's/\|/\\|/g' \|a\|.\|b\|c\| if really want to search for a "|", use the open square brackets Code:
# echo "a.bc" | sed -e 's/[|]/\\|/g' a.bc # echo "a|bc" | sed -e 's/[|]/\\|/g' a\|bc |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
|||
|
|||
|
Humm, seems to be a GNU sed-ism
Under Interix 6.0 and ksh-93 and the OOB sed (non-GNU), it works as expected Code:
$ echo a.bc | sed -e "s/\|/\\|/g" a.bc $ |
|||
| Google The UNIX and Linux Forums |