Thread View: comp.unix.shell
4 messages
4 total messages
Started by lubkt
Sat, 01 Dec 1990 23:12
sed help
Author: lubkt
Date: Sat, 01 Dec 1990 23:12
Date: Sat, 01 Dec 1990 23:12
11 lines
805 bytes
805 bytes
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. /Binod. -------------------- Binod Taterway bt00@pl118a.cc.lehigh.edu | bt00@lehigh.bitnet User Consultant, Lehigh University, Bethlehem, PA 18015 (215) 758-3984
Re: sed help
Author: Paul John Falstad
Date: Tue, 04 Dec 1990 18:09
Date: Tue, 04 Dec 1990 18:09
16 lines
1087 bytes
1087 bytes
In article <99.2757f296@vax1.cc.lehigh.edu> lubkt@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 Try: sed '/^xyz:/s/:[^:]*:/::/' $passwd -- From somewhere in front, you hear a repulsive squelching mumble, as if a chattering orangutan has suddenly had its mouth crammed full of earthworms. "You're invading my personal space!" shrieks the travel agent, rearing back from you like an offended snake. She is probably from California.
Re: sed help
Author: Jeff Beadles
Date: Wed, 05 Dec 1990 18:17
Date: Wed, 05 Dec 1990 18:17
26 lines
1298 bytes
1298 bytes
In <99.2757f296@vax1.cc.lehigh.edu> lubkt@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@onion.pdx.com
Re: sed help
Author: Paul Chamberlain
Date: Wed, 05 Dec 1990 23:05
Date: Wed, 05 Dec 1990 23:05
19 lines
1405 bytes
1405 bytes
In article <99.2757f296@vax1.cc.lehigh.edu> lubkt@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@doorstop.austin.ibm.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads