Extract data from two files

aixkshtext processing

I have two files as given below

Output1.csv

201319107648361,12:27:04,12:27:14,0:0:10 secs
201319109089878,12:27:04,12:27:15,0:0:11 secs
201319108968961,12:27:15,12:27:54,0:0:9 secs
201319108686853,12:27:34,12:27:43,0:0:9 secs
.
.
.
n

Output2.csv

201319107648361,200
201319109089878,129
201319108968961,719
201319108686853,412
.
.
.
n

I need to merge these two files in to a single file with one condition i.e if the first field of both the file are same.

For Instance,

If the first value or field of Output1.csv – 201319107648361 is equal to the first field of Output2.csv then need to print the remaining field of the files in to another file.

Desired output file should contain:

201319107648361,12:27:04,12:27:14,0:0:10 secs,200
201319109089878,12:27:04,12:27:15,0:0:11 secs,129
201319108968961,12:27:15,12:27:54,0:0:9 secs,719
201319108686853,12:27:34,12:27:43,0:0:9 secs,412
.
.
.
n

Best Answer

All you need is join

join -t\, <(sort Output1.csv) <(sort Output2.csv)
-or-
join -t "," <(sort Output1.csv) <(sort Output2.csv)

or awk

awk -F, 'FNR==NR{a[$1]=$2;next}{ print $0 "," a[$1]}' Output2.csv Output1.csv
Related Question