Stefan Troeger wrote:
Hi,
On Tue, Dec 28, 1999 at 06:23 -1000, George Toft wrote:
Stefan Troeger wrote:
so I try " ... | sed 's#.*\(\\)\#\1#g' added a " \ " after " ) " ^There's a dot missing. It should read sed 's#.*\(\.\)#\1#g'
Ciao, Stefan
Could someone translate this to English? I've used sed a little bit, but this intrigues me. So I checked man:
s/regexp/replacement/ Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the spe cial character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.
So if the script begins with "s", then a slash must follow, right?
Actually you can use any character instead of a slash here.
echo foo |sed 's/foo/bar/' echo foo |sed 's@foo@bar@' echo foo |sed 's.foo.bar.' echo foo |sed 's|foo|bar|' echo foo |sed 'spfoopbarp' ..
all work the same. See `info sed':
`\%REGEXP%' (The `%' may be replaced by any other single character.)
This also matches the regular expression REGEXP, but allows one to use a different delimiter than `/'. This is particularly useful if the REGEXP itself contains a lot of `/'s, since it avoids the tedious escaping of every `/'. If REGEXP itself includes any delimiter characters, each must be escaped by a backslash (`\').
Ciao, Stefan
OK. I'm 10 points smarter (read Unix Shell Programming about regular expressions). Why did you make the replacement text \1 when . would do? $ echo "./top/001/abcdef.txt" |sed 's#.*\(\.\)#.#g' .txt $ -- George Toft http://www.georgetoft.com -- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com Also check the FAQ at http://www.suse.com/Support/Doku/FAQ/