sed help

Paul Chamberlain tif at doorstop.austin.ibm.com
Thu Dec 6 10:05:24 AEST 1990


In article <99.2757f296 at vax1.cc.lehigh.edu> lubkt at vax1.cc.lehigh.edu writes:
>	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 have no idea what "\??" is supposed to do but this should work:
	sed -e 's/xyz:[^:]*:/xyz::/' $passwd

But this probably isn't what you want since this also will change
a line with "somethingxyz:KJSDKJSDJS:".  You might even want
a more general and more mischevious command like:
	sed -e 's/^\([^:]*\):[^:]*:/\1::/' $passwd

This wil remove the passwords on ALL users.  The expression "[^:]*"
matches the longest string that does not contain a colon.  A common
mistake would be to use an expression that matches more than that.

Paul Chamberlain | I do NOT represent IBM.         IBM VNET: sc30661 at ausvm6
512/838-9662     | This is rumored to work now --> tif at doorstop.austin.ibm.com



More information about the Comp.unix.shell mailing list