Re: comparing two files
On Sat, 29 Dec 2007 17:55:07 -0800, sonal10july wrote:
> Guys,
> I would like to describe the current scenario.
> I got two type of files Primary and secondary. There is only one primary
> file and around hundred secondary files.
>
> Primary.txt Contains two columns i.e name and number of rows
> ================================================== =========
> Currency_exchange|25000
> Sales|21000
> instruments|120000
>
> ================================================== =========
>
>
> Secondary1.txt Contains two columns i.e name and number of rows
>
> ================================================== =========
> Currency_exchange|21000
> Sales|21000
> instruments|120000
>
> ================================================== =========
>
> Secondary2.txt Contains two columns i.e name and number of rows
>
> ================================================== =========
> Currency_exchange|23100
> Sales|21000
> instruments|120000
>
> ================================================== =========
Good so far, you have show us some typical input files.
> There are 100 more secondary files like
> Secondary3.txt,Secondary4.txt.....Secondary100.txt . First column( name)
> contains the same value among all files but second column (number of
> rows) may contain different values.
Useful information - again ful.
> Now, I want to compare each secondary file (i.e
> Secondary1.txt,Secondary1.txt ....so on) with Primary.txt and copy those
> rows in another file where number of rows are not matching. In other
> words I want to figure out where the number of rows in secondary
> files(i.e Secondary1.txt,Secondary1.txt ....so on) are not matching with
> primary (primary.txt)
At this point your request becomes less ful. You didn;t show us the
required output. For instance you say "copy those rows in another file",
do you want a single "another file", or one file for each secondary. Do
you want some information on which secondary the mismatched row came from?
awk -F'|' 'NR==FNR {v[$1]=$2;}
v[$1]!=$2 {print FILENAME,$0}' primary.txt Secondary*.txt > out
may do what you want.
|