awk compare 2 files

Hi i hope some awk gurus here can help me.. here is what i need i have 2 files:

File1
152445 516532 405088.pdf
152445 516533 405089.pdf
152491 516668 405153.jpg
152491 520977 408779.jpg
152491 0 409265.pdf

File2
516532 /tmp/MainStreet_Sum09_Front_FNL.pdf
516533 /tmp/MainStreet_Sum09_Back_FNL.pdf
516668 /tmp/BMRBusinessCard2.jpg
520977 /tmp/BMRBusinessCard.jpg

output
152445 516532 405088.pdf /tmp/MainStreet_Sum09_Front_FNL.pdf
152445 516533 405089.pdf /tmp/MainStreet_Sum09_Back_FNL.pdf
152491 516668 405153.jpg /tmp/BMRBusinessCard2.jpg
152491 520977 408779.jpg /tmp/BMRBusinessCard.jpg
152491 0 409265.pdf

Thanks in advance

hasn't something similar posted by you already been answered here?

yes but i was using 2 lines on both files, can't seem to do it on 3 lines

not sure what you mean by '2 lines' or '3 lines', but what have you tried to so?

hi thanks for the reply,

i missed something during my first post since it was 2 strings only...like:

file1:
a 1
b 2

file2:
1 something
2 nothing

output to:
a 1 something
b 2 nothing

which is diff. from the post above due to file 1 uses 3 strings in a line

Once again, how's that different from this thread?
And if there's any difference, what have you tried so far modifying the original solution?

am i causing trouble? sorry for that. ill try to be much clearer

my first post is:

file1
$1 $2

file2
$1 $2
####################
while my 2nd post is:
file1
$1 $2 $3

file2
$1 $2

i tried join command, but it leaves out some lines: here is the command
maybe it help someone:

join -1 2 -2 1 file1 file2 |gawk '{print $2" "$1" "$3" "$4}'

my problem is it leaves out:

152491 0 409265.pdf in File1, which is i posted above

Can you try to modify the original 'awk' solution to fit your new file layout?

You should be able to do it by yourself if you know of 2 lines...
Try this:

awk 'FNR==NR{a[$1]=$2;next}{print $1,$2,$3,a[$2]}' file2 file1

cheers,
Devaraj Takhellambam

$
$ cat file1
152445 516532 405088.pdf
152445 516533 405089.pdf
152491 516668 405153.jpg
152491 520977 408779.jpg
152491 0 409265.pdf
$
$ cat file2
516532 /tmp/MainStreet_Sum09_Front_FNL.pdf
516533 /tmp/MainStreet_Sum09_Back_FNL.pdf
516668 /tmp/BMRBusinessCard2.jpg
520977 /tmp/BMRBusinessCard.jpg
$
$ join -a 1 -1 2 -2 1 -o 1.1,1.2,1.3,2.2 file1 file2
152445 516532 405088.pdf /tmp/MainStreet_Sum09_Front_FNL.pdf
152445 516533 405089.pdf /tmp/MainStreet_Sum09_Back_FNL.pdf
152491 516668 405153.jpg /tmp/BMRBusinessCard2.jpg
152491 520977 408779.jpg /tmp/BMRBusinessCard.jpg
152491 0 409265.pdf
$
$

tyler_durden

_______________________________________________
"This is your life and it's ending one minute at a time."