sed help

Jeff Beadles jeff at onion.pdx.com
Thu Dec 6 05:17:29 AEST 1990


In <99.2757f296 at vax1.cc.lehigh.edu> lubkt at vax1.cc.lehigh.edu writes:

>A question on sed:
>	I want to replace a string xyz:KJSDKJSDJS: by xyz:: in a
>password file. The string "KJSDKJSDJS" is arbitrary. So I try:
>	sed -e 's/xyz:\??:/xyz::' $passwd
>I guess the regular expression \?? should match any string, but does
>not work. I know I am goofing somewhere. Any hints? Thanks.

This should do what you want:


	sed 's/xyz:[^::][^::]*:/xyz::/' /etc/passwd

Some versions of sed might not need two ':''s in the "[^::]".  
The version that I'm running here complains about non-match strings that are
only one character long, sigh...

The '?' character is not special with sed.  The '.' is to sed, what the '?' is
to the shell.  Your example would change 'xyz:??abc' to 'xyz:abc'.

Hope this helps,

	-Jeff
-- 
Jeff Beadles		jeff at onion.pdx.com



More information about the Comp.unix.shell mailing list