mrimagepueblo
Programmer
I have two files that I would like to lookup id's for and add their corresponding values to the end of a master file. I can do this in Microsoft Access, but don't really want to.
The office file has a structure of Office ID|Office Name|Address|City|... etc.
The agent file has a structure of Office ID|Agent ID|First Name|Last Name|Address|City|... etc.
The office ids are unique.
The agent ids are not unique numbers
I got a script from Annihilannic a long time ago but it doesn't work with this particular situation.
Masterfile.txt (these field positions are not absolute)
xxx|xxx|xxx|123|xxx|xxx|567|xxx|xxx|
xxx|xxx|xxx|999|xxx|xxx|567|xxx|xxx|
Sample data for office (office.txt)
Office ID|Office Name|Office Address|...
123|Starbucks|123 Anywhere St|....
999|McDonalds|456 Main st|...
Sample data for agent (agent.txt)
Office ID|Agent ID|First Name|Last Name|...
123|567|Tom|Sawyer|...
999|567|Huck|Finn|...
here is what I have been using to match agent id's and appending the actual agent name to the end of the file.
awk -F'|' '
FILENAME==ARGV[1] { firstname[$1]=$2 }
FILENAME==ARGV[2] { print $0 firstname[$14] "|" }
' agent.txt masterfile.txt > masterfile_temp.txt
That statement works perfect when the agent ids are unique but put the first agent id it comes across in the file, ignoring any other matches
So my new output would be.
xxx|xxx|xxx|xxx|Starbucks|Tom|Sawyer|
xxx|xxx|xxx|xxx|McDonalds|Huck|Finn|
Any help would be greatly appreciated.
The office file has a structure of Office ID|Office Name|Address|City|... etc.
The agent file has a structure of Office ID|Agent ID|First Name|Last Name|Address|City|... etc.
The office ids are unique.
The agent ids are not unique numbers
I got a script from Annihilannic a long time ago but it doesn't work with this particular situation.
Masterfile.txt (these field positions are not absolute)
xxx|xxx|xxx|123|xxx|xxx|567|xxx|xxx|
xxx|xxx|xxx|999|xxx|xxx|567|xxx|xxx|
Sample data for office (office.txt)
Office ID|Office Name|Office Address|...
123|Starbucks|123 Anywhere St|....
999|McDonalds|456 Main st|...
Sample data for agent (agent.txt)
Office ID|Agent ID|First Name|Last Name|...
123|567|Tom|Sawyer|...
999|567|Huck|Finn|...
here is what I have been using to match agent id's and appending the actual agent name to the end of the file.
awk -F'|' '
FILENAME==ARGV[1] { firstname[$1]=$2 }
FILENAME==ARGV[2] { print $0 firstname[$14] "|" }
' agent.txt masterfile.txt > masterfile_temp.txt
That statement works perfect when the agent ids are unique but put the first agent id it comes across in the file, ignoring any other matches
So my new output would be.
xxx|xxx|xxx|xxx|Starbucks|Tom|Sawyer|
xxx|xxx|xxx|xxx|McDonalds|Huck|Finn|
Any help would be greatly appreciated.