Re: escape characters in sed
Hans du Plooy wrote: william pursell wrote: Your version is missing the final ', so I'm guessing you meant: sed 's/\\)/ /' Yes, sorry, several mistakes on my part... which will replace occurences of \) with a single space Not what I had intended, I just wanted to replace ) with a space. Actually I wanted to replace the ( with a space and get rid of the trailing ), So, you'd want to use: sed -e 's/(/ /' -e 's/)//' Which says replace left parens with a space, right one with nothing, with a single run of 'sed'. : eg: $ echo '2nd backslash and first paren replaced: \\))' | sed 's/\\)/ /' 2nd backslash and first paren replaced: \ ) Note that this is exactly the same as: $ echo '2nd backslash and first paren replaced: \\))' | sed s/\)/\ / 2nd backslash and first paren replaced: \ ) Thanks, now I kinda understand why. Hans Bob smime.p7s Description: S/MIME Cryptographic Signature
Re: escape characters in sed
On Mon, May 14, 2007 at 08:59:49AM -0700, Bob McGowan wrote: Hans du Plooy wrote: william pursell wrote: Your version is missing the final ', so I'm guessing you meant: sed 's/\\)/ /' Yes, sorry, several mistakes on my part... which will replace occurences of \) with a single space Not what I had intended, I just wanted to replace ) with a space. Actually I wanted to replace the ( with a space and get rid of the trailing ), So, you'd want to use: sed -e 's/(/ /' -e 's/)//' any reason not to do sed -e 's/(/ /;s/)//' Which says replace left parens with a space, right one with nothing, with a single run of 'sed'. : eg: $ echo '2nd backslash and first paren replaced: \\))' | sed 's/\\)/ /' 2nd backslash and first paren replaced: \ ) Note that this is exactly the same as: $ echo '2nd backslash and first paren replaced: \\))' | sed s/\)/\ / 2nd backslash and first paren replaced: \ ) Thanks, now I kinda understand why. Hans Bob signature.asc Description: Digital signature
Re: escape characters in sed
Alex Samad wrote: On Mon, May 14, 2007 at 08:59:49AM -0700, Bob McGowan wrote: Hans du Plooy wrote: william pursell wrote: Your version is missing the final ', so I'm guessing you meant: sed 's/\\)/ /' Yes, sorry, several mistakes on my part... which will replace occurences of \) with a single space Not what I had intended, I just wanted to replace ) with a space. Actually I wanted to replace the ( with a space and get rid of the trailing ), So, you'd want to use: sed -e 's/(/ /' -e 's/)//' any reason not to do sed -e 's/(/ /;s/)//' ---XXX--- No, except perhaps clarity. And, the fact I was not aware that you could do it that way. ;) Bob smime.p7s Description: S/MIME Cryptographic Signature
escape characters in sed
Hi guys, I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / But it does nothing. Why? How do I do this? Thanks Hans -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hans du Plooy escribió: Hi guys, I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / But it does nothing. Why? How do I do this? Well, I think you're replacing `)' and not `(' Jose Luis. - -- ghostbar on Linux/Debian 'sid' i686 - #382503 Weblog: http://ghostbar.ath.cx/ - http://linuxtachira.org http://debian.org.ve - irc.debian.org #debian-ve #debian-devel-es San Cristóbal, Venezuela. http://chaslug.org.ve Fingerprint = 3E7D 4267 AFD5 2407 2A37 20AC 38A0 AD5B CACA B118 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGRyepOKCtW8rKsRgRAp4zAKDONrTYYgU/7ZO+elcQWzukBLHviwCggxsS uKsfS6DepSlsl4yikeUnmk8= =vKDP -END PGP SIGNATURE- -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
Jose Luis Rivas Contreras wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hans du Plooy escribió: Hi guys, I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / But it does nothing. Why? How do I do this? Well, I think you're replacing `)' and not `(' Typo, sorry. Should be: sed 's/\\(/ /' Still doesn't work though :-) I guess the question should be, how to excape a ( character? Thanks Hans -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
Hi Hans. Hans du Plooy, 13.05.2007 16:51: I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / No, just type the parenthesis, no escaping necessary. Regards, Mathias -- debian/rules signature.asc Description: OpenPGP digital signature
Re: escape characters in sed
Hans du Plooy wrote: I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / But it does nothing. Why? How do I do this? $ echo 1.2.3.4(1.2.3.4) | sed 's/(/ /' 1.2.3.4 1.2.3.4) $ echo 1.2.3.4(1.2.3.4) | sed s/\(/\ / 1.2.3.4 1.2.3.4) Your version is missing the final ', so I'm guessing you meant: sed 's/\\)/ /' which will replace occurences of \) with a single space: eg: $ echo '2nd backslash and first paren replaced: \\))' | sed 's/\\)/ /' 2nd backslash and first paren replaced: \ ) Note that this is exactly the same as: $ echo '2nd backslash and first paren replaced: \\))' | sed s/\)/\ / 2nd backslash and first paren replaced: \ ) Try the exercise of replacing the quote marks in the echo with double-quotes. Hours of fun for the whole family! -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
Hans du Plooy wrote: Typo, sorry. Should be: sed 's/\\(/ /' Still doesn't work though :-) I guess the question should be, how to excape a ( character? With a backslash! The thing is, if you include the single quotes, you don't need to escape it through the shell, but if you drop the single quotes, you do. Also, since you are escaping the backslash to sed, you are telling sed to look for a literal backslash. When sed sees an unescaped (, it looks for it literally. When it sees an escaped (, it uses it as a grouping symbol. In other words: the shell and sed both treat backslash as a special character, but only the shell treats ( as a special character. Suppose you want to replace the literal text a (fat) cat with a cat: $ echo a (fat) cat | sed 's/(fat) //' a cat However, this replaces all occurences of (fat) , which may not be what you want, so you do a grouping: $ echo a (fat) cat | sed 's/\(a\) (fat) \(cat\)/\1 \2/' a cat Here, we use '(' to match literal '(', and '\(' to tell sed that we want to remember that portion of the regex, for use in the replacement string. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
Mathias Brodala wrote: Hi Hans. Hans du Plooy, 13.05.2007 16:51: I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / No, just type the parenthesis, no escaping necessary. Thanks Mathias - guess I was trying to be too smart :-) Hans -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
william pursell wrote: Your version is missing the final ', so I'm guessing you meant: sed 's/\\)/ /' Yes, sorry, several mistakes on my part... which will replace occurences of \) with a single space Not what I had intended, I just wanted to replace ) with a space. Actually I wanted to replace the ( with a space and get rid of the trailing ), : eg: $ echo '2nd backslash and first paren replaced: \\))' | sed 's/\\)/ /' 2nd backslash and first paren replaced: \ ) Note that this is exactly the same as: $ echo '2nd backslash and first paren replaced: \\))' | sed s/\)/\ / 2nd backslash and first paren replaced: \ ) Thanks, now I kinda understand why. Hans -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: escape characters in sed
Hans du Plooy wrote: Jose Luis Rivas Contreras wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hans du Plooy escribió: Hi guys, I'm trying to do a search/replace on some text. Looks like this: 1.2.3.4(1.2.3.4) To my mind, this should replace the '(' with a space sed 's/\\)/ / But it does nothing. Why? How do I do this? Well, I think you're replacing `)' and not `(' Typo, sorry. Should be: sed 's/\\(/ /' Still doesn't work though :-) I guess the question should be, how to excape a ( character? Thanks Hans I think you have too many \, try sed 's/\(/ /' That is the way it would be done in perl, vim, etc. but sed may be different! ;-) Good Luck! Dennis -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]