![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sort command - strange behaviour | miwinter | UNIX for Advanced & Expert Users | 16 | 05-29-2008 07:19 AM |
| Longer commands and strange behaviour on ksh | anurags | UNIX for Dummies Questions & Answers | 2 | 03-27-2008 11:04 AM |
| A Strange Behaviour!!! | navojit dutta | Shell Programming and Scripting | 5 | 12-21-2007 04:35 AM |
| /etc/passwd strange behaviour! | penguin-friend | Linux | 0 | 06-06-2005 12:00 PM |
| very strange behaviour on unix server | bolo77 | UNIX for Dummies Questions & Answers | 7 | 03-02-2005 03:32 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
|||||
|
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 ? |
|
||||
|
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 |
|
||||
|
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 |
|
|||||
|
Quote:
|
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|