[sllug-members]: Script Question
Roger Smith
roger at itigger.com
Mon May 5 10:51:12 MDT 2008
On Monday 05 May 2008 10:44:37 am Jason Clint wrote:
> I am trying to do a Linux script to compare 2 files in some way and only
> return a certain result.
>
> File 1 = /etc/passwd
> File 2 = nonusers.txt
>
> File 2 has all the nonusers in it and I need to make sure my script
> doesn't accidently pull out any of them. This is a for a manual ldap
> import and when I ran the script the first time I had a user named "ns"
> so it pulled out "ns" and "nscd" which is a nonuser. Anyway I was
> trying to use a script to compare the 2 and only return a result that
> didn't have "nologin" or even just return all results except the ones
> that were in the status list nonusers.txt. I'm kind of new at shell
> scripting so any help would be greatly appreciated.
diff works, assuming the orders are the same. This is another way of going
about it.
# define files to compare
File1 = /etc/passwd
File2 = nonusers.txt
# list all login entries : show unique entries and count how often they
# appear : show entries that appear once
cat $File1 $File2|grep -v nologin| sort |uniq -c|grep -E "[[:space:]]+1\
[[:space:]]"
# list all login entries : show unique entries and count how often they
# appear : only show entries that appear twice
cat $File1 $File2|grep -v nologin| sort |uniq -c|grep -E "[[:space:]]+2\
[[:space:]]"
-- Roger
More information about the sllug-members
mailing list