Match file and find count

Hi All,

I have transaction in one file.I want to match that to another file and find the number of time the transaction is available on the other file.I need to take each record from TRANSFILE and match that with SPEND FILE and find the number of counts of the transaction

TRANSFILE:

1000189376
100500004296
1013558744
1013558748
1013558861
1019100045
1019135000
1025088101

SPEND FILE:

1450001254;5.79
2114014282;3.18
1013558744;1.89
1013558744;3.29
2114021154;0.60
2114021220;0.73
2114026059;2.69
2114026118;2.29
2114027918;1.69
1019135000;1.06

Output should be like

1000189376 ----->0
100500004296 ---->0
1013558744 ----->2
1013558748 ----->0
1013558861----->0
1019100045 ----->0
1019135000 ----->1
1025088101----->0

Try:

awk 'NR==FNR{C[$1]++; next} {printf "%-13s----->%s\n", $1, C[$1]+0}' FS=\; sendfile FS=" " transfile
1 Like

Just to bring your attention about the fact that Scrutinizer's code assumes that multiples occurrences of a transaction in "spend file/sendfile" must be sequential ... (since the display of computing is dynamic rather than post-processed in an END{...} block )

Why must they be sequential @ctsgnb? An array is used to count the occurrence in the spend file and in a way "post processed" while reading the transfile... No matter how the records in the spend file are arranged, the outcome is the same..

You are right, but another warning is in order: because the processing is done in memory the script has - depending on the sizes of the files involved - the potential to exhaust the systems memory if the files are very big and/or the RAM is small.

I hope this helps.

bakunin