|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|
|||
escape single quote in sed
I've googled the all world, but can't find the answer to this question:
I need to replace in a file s' (s plus single quote) with another character (one character in the place of two). I tried this (and many other variants): Code:
sed 's/s\'/X/' file > newfile Code:
> |
|
|||
Code:
sed s/s\'/X/ file > newfile |
|
|||
actually, I just found out it also works in ksh (OpenBSD defalut shell).
I'm not a programmer, and in all the tutorials and howtos the commands after sed are inside single quotes. Now I took them away and it works. I'm confused |
|
|||
even more confused now.
In the same file I need to add \\ at the end of each line to use it in latex, in this case I must put the sed command in single quotes, otherwise the same command would give only one back slash: sed 's/$/\\\\/g' file > newfile (gives expected output) sed s/$/\\\\/g file > newfile (only adds one backslash) why? |
|
|||
Recognize that the command is being passed from the shell to sed, & each consumes a leading backslash as an "escape" if given the chance. The reason single quotes works is because this tells the shell that the enclosed string is to be passed to sed as is without the shell consuming the leading backslash(s).
In other words, enclosing the argument in single quotes actually passes the necessary information on to sed. |
|
|||
yeah, makes sense
tks |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Remap colour escape codes | bsdperson | FreeBSD General | 2 | 14th September 2009 10:52 AM |
I need to set up a firewall and DNS server on a single computer HELP PLEASE | kla | OpenBSD General | 8 | 4th June 2009 08:38 PM |
Single instance of VLC player | maxrussell | General software and network | 1 | 8th February 2009 03:57 PM |
can't get out of twm - any escape? | Lazy | FreeBSD General | 4 | 28th June 2008 07:26 PM |