[sllug-members]: Script Question
Jason Clint
jason_clint at sento.com
Mon May 5 11:16:09 MDT 2008
I agree with roger the problem with diff is that the files may or may
not be in the same order. I worked trying to use diff for a bit and it
requires a lot of trimming once you get the results.
Roger with this script you gave me it seems you define the files
"$file1=somefile", "$file2=someotherfile". Then you go in and cat,
grep, sort and grep again all in one command. First so I can understand
how this is done can you explain what this command does "[[:space:]]+2\
[[:space:]]" does that tell it to ignore the space?
Thanks.
Junior Systems Administrator
Sento IT Jason Clint
(801) 431-9297
(801) 661-4139
-----Original Message-----
From: Roger Smith [mailto:roger at itigger.com]
Sent: Monday, May 05, 2008 10:51 AM
To: sllug-members at sllug.org
Cc: Jason Clint
Subject: Re: [sllug-members]: Script Question
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