Hi All,
I have two txt files like this
File1:
no name
----------
12 aaaa
23 bbbb
55 cccc
File2
dname dno
------------
civil 33
mech 55
arch 66
Now i want to compare col1 from File and col2 from File2, if its match i want fetch all columns from two files.
Expected output:
no name dname dno
----------------------
55 cccc mech 55
How can we do that?
help me on this
Thanks
MPS
Use nawk, /usr/xpg4/bin/awk or gawk on Solaris:
awk 'NR == FNR {
_[$1] = $0
next
}
$2 in _ {
print _[$2], $0
}' file1 file2
Hi radoulov,
its giving some "Parse" error when i issue the code in command prompt as well as i tried with awk script lik this.
$ cat com.awk
{
NR == FNR {
_[$1] = $0
next
}
$2 in _ {
print _[$2], $0
}
}
then in Command prompt
$ awk -f com.awk file1 file2
even though its not working.
Thanks
MPS
Did you try with nawk/XPG awk as suggested? What platform you're using?
P.S. The content of com.awk is wrong, you should remove the outer braces.