![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk - comparing files | dbrundrett | Shell Programming and Scripting | 6 | 01-18-2009 10:51 PM |
| Comparing two files | ragavhere | Shell Programming and Scripting | 32 | 12-04-2008 01:24 PM |
| Comparing two files | superstar003 | Forum Support Area for Unregistered Users & Account Problems | 1 | 05-08-2008 04:34 AM |
| Comparing two files.. | padarthy | Shell Programming and Scripting | 1 | 08-29-2007 09:01 AM |
| comparing shadow files with real files | terrym | UNIX for Advanced & Expert Users | 4 | 02-09-2007 02:38 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Comparing two files...
I searched through the forums, and there are a couple threads that have a similar problem to mine, but they don't seem to exactly address my problem. I'm running an HP-UX box, trying to create a little script that will compare the /etc/passwd file with another file I have created. Each line in this file, let's call it /etc/myusers, has a pin that the user has chosen (not necessarily unique), then their userid, then the comments field from /etc/passwd. (basically their full name, phone number, all that jazz. Here is an example: Quote:
I basically want to make sure that every account in my /etc/passwd file is also in this file. So all I want to do is go through each line in /etc/passwd, and search for each userid in this custom file. If the name DOESN'T exist in my custom file, I want to print it out (from /etc/passwd) to the screen, or a file, or whatever, so I can go through and add all the accounts to this file. It should be fairly simple, I just can't quite figure it out. I was thinking of just doing an awk on the /etc/passwd file and pulling out all the usernames to a file, and then doing a for loop through that file, or something like this: Code:
root# awk -F: '{ print $1 }' /etc/passwd > users.txt
root# for x in `cat users.txt` ; do
>grep $x /etc/myusers
>if no result, print to file or whatever...?
Just not quite sure what. Thanks for your help. |
|
||||
|
Quote:
What I need is a nice clean output of simply the lines in /etc/password that do not have a corresponding userid in /etc/myusers. |
|
||||
|
Quote:
Code:
>cat passwordfile pin:userid:comments: 9876:clooneyg:"George Clooney,Los Angeles CA,123-123-1234": 1652:simpsonh:"Homer Simpson,Los Angeles CA,123-123-1234": Code:
>cat userfile pin:userid:comments: 1234:pittb:"Brad Pitt,Los Angeles CA,123-123-1234": 9876:clooneyg:"George Clooney,Los Angeles CA,123-123-1234": 6548:dansont:"Ted Danson,Los Angeles CA,123-123-1234": 9685:owenc:"Clive Owen,Los Angeles CA,123-123-1234": 1652:simpsonh:"Homer Simpson,Los Angeles CA,123-123-1234": Code:
awk -F":" 'BEGIN{ while(getline < "passwordfile") { arr[$2]=i++ } }{ for ( i in arr ) { if ( i == $2 ) { cnt=1} } if ( cnt != 1 ) { print } cnt=0; }' userfile
Code:
1234:pittb:"Brad Pitt,Los Angeles CA,123-123-1234": 6548:dansont:"Ted Danson,Los Angeles CA,123-123-1234": 9685:owenc:"Clive Owen,Los Angeles CA,123-123-1234": Hope this is what you had asked for! |
|
||||
|
one good logic is to ...cut and have column 2nd then 1st on each line from passwd file and redirect the output to file lets say a1. Then do the same on other passwd file and save the file as a2. Sort both file one by one and redirect output to a1sorted and a2sorted. Now run "sdiff a1sorted a2sorted"
and it will show you where we have extra members or less members.. arun Quote:
|
![]() |
| Bookmarks |
| Tags |
| awk, perl script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|