match columns using awk

Hi All,

I need some help in writing a small script using Awk.

My input file has following deatils
A,B,C,D
8239359,8239359,8388125,8388125
8239359,8239359,8388125,8388125
7165981,7165981,8363138,8363138
8283830,8283830,8382987,8382987
8209964,8209964,8367098,8367098
8279587,8279587,8345975,8345975
8283830,8283830,8382987,8382987

My aim is to get the following output
If a=b(any line column) then search (c=d) and print a,b,c,d
please note that the numbers a,b,c,d are not sorted

I would appreciate the help.

Best Regards
Pistachio

If you mean a==b and c==d on the same line:

awk -F, '{ if($1==$2 && $3==$4) {print $0}  }'  inputfile

... and if you mean something different, please post an example of the desired output.

Hi Jim ,

My input file basically consist of two files where a,c are part of one file and b and d are part of other file.I need to get only thoes records which bascally match a is equal to b (anywhere in the column) and c is in the same line as b is should be equal to d(anywhere in the coulmn) and then print all a,b,c,d

Appreciate the help in advance

Please give two short input file examples, plus the expected output.

He guys thanks for the help

but let me try to explain this better.

If a==b then only check if c==d otherwise skip the record.
input
8239359,8239359,8388125,8388125
8283830,8283831,8382988,8382988
8283830,,8382987,
8283831,8283830,8382987,8382987
8209964,8209965,8367099,8367098
8209965,8209964,8367098,8367098
8209964,8209965,8367098,8367099

output
8239359,8239359,8388125,8388125
8283830,8283830,8382987,8382987
8283831,8283831,8382988,8382988
8209964,8209964,8367098,8367098
8209965,8209965,8367098,8367098

Best Regards
Pistachio

You said at the start: two input files. one output file. This is very confusing for me.

Hi Pistachio,

let me confirm once again...according to your sample..are you looking for the combination like below...

input:

a1 b1 c1 d1
a2 b2 c2 d2
a3 b3 c3 d3

output
a1 b2 c2 d3 (incase if a1=b2, c2=d3)
a2 b3 c1 c2 (incase if a2=b3, c1=c2)..

is that way you need output...

:rolleyes:

Thanks
Sha

Hi,

if the question above is true then..
here is the code which may help you...

awk '{a[$1]=a[$2]$0","}
END {for (i in a) {print a[i]} }' input file|awk '{a[$3]=a[$4]$0"\n"}
END {for (i in a) {print a[i]} }'

Thanks
Sha:b: