![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| compare files | prashanth.spl | Shell Programming and Scripting | 0 | 06-18-2008 04:22 PM |
| compare files | danabo | Shell Programming and Scripting | 3 | 05-19-2008 12:09 PM |
| compare two files | charandevu | Shell Programming and Scripting | 7 | 03-30-2008 03:20 PM |
| Compare two files | penfold | Shell Programming and Scripting | 3 | 04-28-2005 11:04 PM |
| compare files and beyond | MizzGail | UNIX for Dummies Questions & Answers | 2 | 04-25-2003 01:34 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Compare two files
I need to compare two files:
Basically I have an input file fileA. which need to be compare with fileB located in /etc/lc/mbd directroy Both file format is like: abc01def:10.80.11.123 The input file format is: abc01mns:10.80.11.1 dbc02mns:10.80.11.2 fbc01mns:10.80.11.3 rbc01mns:10.80.11.4 tbc01mps:10.80.11.5 abt05mns:10.80.11.6 zbc11mys:10.80.11.7 ttc01mns:10.80.11.8 hbc05mns:10.80.11.9 qbc01mns:10.80.11.10 So after comparison the script will tell me: what has been dupicate and what not duplicate. Thanks |
|
||||
|
Thanks.,
This approach works, what do you think: #!/bin/ksh while read myline do cnt=0 while read line do if [[ "$myline" = "$line" ]] then ((cnt+=1)) break fi done < file1 if [[ $cnt -eq 0 ]] then echo "$myline" >> output.file fi done < file2 |
|
||||
|
The diff command seems ideal for this. In particular:
Code:
diff -y file1 file2 |
|
||||
|
Try this, the result is stored in the files dup_file and no_dup_file:
Code:
awk 'NR==FNR{a[$0]=$0;next}
$0 in a {print $0 > "dup_file";next}
{print $0 > "no_dup_file"}
' fileA fileB
Regards |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|