Hello everyone,
I have 3 files that I need to deal with and create 1 single file from all of them.
myfirst file looks like:
00001
00002
00003
00004.... and what ever numbers this file contains is what I need to process against.
mysecond file looks like:
"00001","a description","character","size","F",.....
"00002","a, description","character","size","F",.....
"00003","a description","character","size","F",.....
"00004","a, description","character","size","F",.....
...
...
I need to process myfirst file against mysecond file and when it finds the matches from the first field, awk will write the compared field, second field and fourth field to mynewfile.
The issue that I'm having is that when I started, I used the comma as the FS which created a problme becuase the second field sometimes has a comma eventhough is 1 field so it throws off my logic below:
awk -F, '
NR==FNR{a[$1]=$0;next}
{for(i in a)if($1~i){print a" " $2"--"$4 ;next}}
' myfirst mysecond >>newfile
When the above is ran, the fields are written incorrectly when an extra comma is encountered in the second field of the second file.
I tried changing "-F," to "-F" "" and all I get is the comparing number and a bunch of "--" through out the new file.
I'm expecting:
00001 a description -- size
and I'm getting:
00001 a -- character
or
00001 ---
Could you please tell me how to solve for that?
Finally, mythird file looks like:
"00001","11.234","03/18/1998"
"00002","11.234","03/18/1998"
"00003","11.234","03/18/1998"
"00004","11.234","03/18/1998"
...
...
Could you tell me how to make the 2nd field on the thirdfile the last field on my newfile (of course matching the first field between the two files) once the first problem is resolved?
Thank you in advance for all your help and sorry for the long note.
Orale!
I have 3 files that I need to deal with and create 1 single file from all of them.
myfirst file looks like:
00001
00002
00003
00004.... and what ever numbers this file contains is what I need to process against.
mysecond file looks like:
"00001","a description","character","size","F",.....
"00002","a, description","character","size","F",.....
"00003","a description","character","size","F",.....
"00004","a, description","character","size","F",.....
...
...
I need to process myfirst file against mysecond file and when it finds the matches from the first field, awk will write the compared field, second field and fourth field to mynewfile.
The issue that I'm having is that when I started, I used the comma as the FS which created a problme becuase the second field sometimes has a comma eventhough is 1 field so it throws off my logic below:
awk -F, '
NR==FNR{a[$1]=$0;next}
{for(i in a)if($1~i){print a" " $2"--"$4 ;next}}
' myfirst mysecond >>newfile
When the above is ran, the fields are written incorrectly when an extra comma is encountered in the second field of the second file.
I tried changing "-F," to "-F" "" and all I get is the comparing number and a bunch of "--" through out the new file.
I'm expecting:
00001 a description -- size
and I'm getting:
00001 a -- character
or
00001 ---
Could you please tell me how to solve for that?
Finally, mythird file looks like:
"00001","11.234","03/18/1998"
"00002","11.234","03/18/1998"
"00003","11.234","03/18/1998"
"00004","11.234","03/18/1998"
...
...
Could you tell me how to make the 2nd field on the thirdfile the last field on my newfile (of course matching the first field between the two files) once the first problem is resolved?
Thank you in advance for all your help and sorry for the long note.
Orale!