Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP SIMPLIFYING SED COMMANDS

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
This section of a script uses sed to remove multiple user accounts. I'd like to make that a more compact sed line rather than having multiple pipes, however I can only use awk and sed; no perl.

cp -p $ROOT_DIR/etc/shadow $ROOT_DIR/etc/shadow.pre_smtp_removal
cp -p $ROOT_DIR/etc/shadow /tmp/.
sed -e '/^smtp/d' /tmp/shadow | sed -e '/^uucp/d' | sed -e '/^nuucp/d'| | sed -e '/^listen/d' | sed -e '/^nobody/d' | sed -e '/^nobody4/d' > $ROOT_DIR/etc/shadow


Any help would be greatly appreciated.

Thanks,

John
 
Well, as long as the names do not change you could use this:

cp -p $ROOT_DIR/etc/shadow $ROOT_DIR/etc/shadow.pre_smtp_removal
cp -p $ROOT_DIR/etc/shadow /tmp/.

for NAME in smtp uucp nuucp listen nobody nobody4
do
sed "/^${NAME}/d" /tmp/shadow > /tmp/TEMP
mv -f /tmp/TEMP /tmp/shadow
done

mv -f /tmp/shadow $ROOT_DIR/etc/shadow


This really isn't anymore compact, but a little nicer to read...question though? Why bother to fix it if it isn't broken? I think you would be better off just leaving it, unless some other reason is there that wasn't posted.
 

sed -e '/^smtp/d;/^uucp/d;/^listen/d;/^nobody/d' inputfile > outputfile
mv outputfile inputfile

OR

egrep -v "smtp|uucp|listen|nobody" inputfile >outputfile
mv outputfile inputfile

sed is better, -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Code:
cp -p $ROOT_DIR/etc/shadow $ROOT_DIR/etc/shadow.pre_smtp_removal
cp -p $ROOT_DIR/etc/shadow /tmp/.
sed -e '/^\(smtp|uucp|nuucp|listen|nobody4?\)/d' /tmp/shadow > $ROOT_DIR/etc/shadow
should work too. //Daniel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top