![]() |
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 |
| comparison of 2 files | kamal_418 | Shell Programming and Scripting | 2 | 08-04-2008 06:05 AM |
| need some help..Comparison | bluesilo | Shell Programming and Scripting | 0 | 02-23-2008 04:43 PM |
| Comparison of 2 files in UNIX | Dana Evans | UNIX for Dummies Questions & Answers | 32 | 11-21-2007 07:05 AM |
| Comparison of two files in awk | jerome Sukumar | Shell Programming and Scripting | 12 | 07-26-2006 08:16 AM |
| String Comparison between two files using awk | rudoraj | Shell Programming and Scripting | 7 | 07-25-2006 11:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Dear All,
I want to compare two csv files using shell programming - File 1 contents 44,,NONE,0,,2/2/1901 66,,NONE,0,,2/3/1901 File 2 Contents 1022,3708268,AUFX,0,100919,3/1/2006 66,,NONE,0,,2/3/1901 After comparing each column/field I want to print the occurances of difference for each field/column i.e suppose if 44 and 1022 doesn't match then it will be 1, suppose if it matches then it will be 0. My ultimate goal is to count the total number of differences for each field. Any help will be highly appreciated. |
|
||||
|
Hi,
Try this one. input: Code:
a: a,30,c b,30,c d,27,c b: a,29,f b,30,c e,26,f Code:
Filed1 mismatch:1 Filed2 mismatch:2 Filed3 mismatch:2 Code:
paste -d"," a b | awk 'BEGIN{FS=","}{
if($1!=$4)
a++
if($2!=$5)
b++
if($3!=$6)
c++
}
END{
print "Filed1 mismatch:"a"\n"
print "Filed2 mismatch:"b"\n"
print "Filed3 mismatch:"c"\n"
}'
|
|
||||
|
Comparing two csv files
Thanks a lot Summer for this code. This is working fine. I want to put the result in a log file. Thats why I have used echo "">log.txt. But this is not working. I have tried with print "">log.txt also but with no result. Any idea if I want to put this in a log file.
|
|
||||
|
Can you post a sample of the input and its output.
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| compareing two csv files, comparing each field of a csv file, finding the count difference |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|