jimmy_y
1
Hi Everyone,
1.txt
00:01:01 asdf
00:33:33 1234
00:33:33 0987
00:33:33 12
00:33:33 444
2.txt
vvvv|ee
444|dd33|ee
dddd|ee
12|ee
3ciur|fdd
the output should be:
00:33:33 12;12|ee
00:33:33 444;444|dd33|ee
means if 1.txt line can be found in 2.txt, then print both line seperated by ";".
Please advice.
Thanks
awk -F\| 'NR == FNR {
k[$1] = ";" $0; next
}
$2 in k && $0 = $0 k[$2]
' 2.txt FS='[ \t]*' 1.txt
jimmy_y
3
---------- Post updated at 05:52 AM ---------- Previous update was at 05:41 AM ----------
Hi radoulov,
if my 2.txt change to
vvvv|ee
qqqqq444|dd33|ee
dddd|ee
qq33f12|ee
3ciur|fdd
how to output the same result
And 1.txt remains the same?
---------- Post updated at 11:58 AM ---------- Previous update was at 11:55 AM ----------
awk -F\| 'NR == FNR {
k[$1] = ";" $0; next
}
{
for (K in k)
if (K ~ $2) {
print $0 k[K]
break
}
}
' 2.txt FS='[ \t]*' 1.txt
jimmy_y
5
print $0 k[K] should be print $0; k[K];
Thanks, it works so perfect i learn a lot awk.
---------- Post updated at 08:50 AM ---------- Previous update was at 08:36 AM ----------
But seems this has a bug.
1.txt (add the 1st line)
iiiii
00:01:01 asdf
00:33:33 1234
00:33:33 0987
00:33:33 12
00:33:33 444
2.txt (no change)
vvvv|ee
qqqqq444|dd33|ee
dddd|ee
qq33f12|ee
3ciur|fdd
the output is
awk -F\| 'NR == FNR {k[$1] = ";" $0; next} {for (K in k) if (K ~ $2) {print $0 k[K]; break}}' 2 FS='[ \t]*' 1
iiiii;vvvv|ee
00:33:33 12;qq12|ee
00:33:33 444;qq444|dd33|ee
as you can see extra "iiii;vvvv|ee" here, but it should not be there.
where should i put "if (NR!=1)"...
Thanks
Try this one:
awk -F\| 'NR == FNR {
k[$1] = ";" $0; next
}
NF > 1 {
for (K in k)
if (K ~ $2) {
print $0 k[K]
break
}
}
' 2.txt FS='[ \t]*' 1.txt