[PLUG] shell scripting problem
David Fleck
dcf at aracnet.com
Fri Jun 7 02:25:31 UTC 2002
On Thu, 6 Jun 2002, Matt Alexander wrote:
> I have about 200 names in /etc/group that I want to remove. They're all
> under a generic "users" group. I have a file that contains the names that I
> want to remove, and I'm looking for a wizbangwowzerz *nix way to read in
> all those names and delete them from the group file. I'll also need to
> delete the comma after each name.
How about:
#!/bin/sh
namefile=$1
infile="/etc/group"
temp1="temp1"
temp2="output"
cp ${infile} ${temp1}
while read user;
do
sed -e "s/${user},//" -e "s/[^^]${user}//" ${temp1} > ${temp2}
cp ${temp2} ${temp1}
done < $namefile
sed -e "s/,$//" ${temp1} > ${temp2}
rm ${temp1}
exit 0
the script would be given an argument representing the names list file,
and would put the output into 'output'; e.g., 'script.sh namelist'.
--
David Fleck
dcf at aracnet.com
More information about the PLUG
mailing list