grep, awk, nawk combo

I have 2 files:

File1
"aa","server","001-9031234-001",

File2
001-9031234-001|12345

Both files have many lines of text. Each line needs to be evaluated. I need to look at the value of the third field in File 1. Then look for that same value in File 2 and assign the value of Field 2 in that file to num.

so num for this example would equal 12345. The value of num would then be input back into File1 so File1 would then look like
"aa","server","001-9031234-001","12345",

:confused:
Thanks,

Hi,

Try this:

 awk -F"[,|]" 'NR==FNR{s["\"" $1 "\""]=$2;next}{printf "%s\"%s\"\n", $0, s[$3]}' file2 file1

When I try that, the output looks like it appends File2 to File 1.

#more test.sh
#!/usr/bin/sh
awk -F"[,|]" 'NR==FNR{s["\"" $1 "\""]=$2;next}{printf "%s\"%s\"\n", $0, s[$3]}' File2 File1

then I run ./test.sh /tmp/test.txt

It works on the sample file you gave on your first post. If real files differ please post realistic sample files.

Also, just try to run the command like this:

$ awk -F"[,|]" 'NR==FNR{s["\""$1"\""]=$2;next}{printf "%s\"%s\"\n", $0, s[$3]}' file2 file1

Ah ha. I am running solaris and if you use the awk in /usr/xpg4/bin, you are correct it does work. The awk in /usr/bin does not work.

Thanks so much!
:):b::b::b::b::b:

---------- Post updated at 04:46 PM ---------- Previous update was at 04:16 PM ----------

Quick question - which part of the awk tells it to append it to the end of the file. What if you wanted it to be say the second field in the file?

---------- Post updated at 04:51 PM ---------- Previous update was at 04:46 PM ----------

Quick question:
which part of the awk tells it to append it to the end of the file. What if you wanted it to be say the second field in the file?

{printf "%s\"%s\"\n", $0, s[$3]}