Hi,
Would anyone be able to suggest on this shell script query? =)
From the contents of the 2 sample files below, if both files' 1st fields matched (ex: XYZ1234=XYZ1234), I want to append the 4th field (semi-colon delimited) from File2 to the end of that line in File1.
If no match found, then simply append 0000.00 (zero)
File1:
XYZ1234 |Golden State | 500000.00| 10-JUNE-2008| 0654321|Model Railroad Museum
ABC5678 |Philadelphia | 350000.50| 10-JUNE-2008| 0135790|Avenue of Arts
LMN3579 |Seattle | 1180000.00| 15-JUNE-2008| 0427508|Elysian Brewing
RQP8642 |Charlotte | 98500.50| 17-JUNE-2008| 0315386|Paramount's Carowind
TYU4938 |Milwaukee | 85000.50| 17-JUNE-2008| 0526874|Betty Brinn Museum
Hi Sir Franklin,
Sincerely appreciate your response.
I actually have a little idea of how i want to go about this, but i just seem to have a hard time putting everything exactly in code.
I want to loop the File1 line by line (storing the 1st fields, i.e XYZ1234) then use this variable to search in File2, and then get the 5th field from that same equation.
Ex: grep XYZ1234 File2 | awk -F";" '{print $4}'
Then will append that output to the end of the 1st line in File1.
Same will be done for the rest of the lines in File1.
i=1
while true
do #Get the line from File1
line=`sed -n ${i}p File1`
\#Get the first field in the line
code=\`echo $line | cut -d'|' -f1\`
\#EOF
if [ -z "$code" ]
then
exit 0;
fi
\#Get the 4th field of the File2
data=\`sed -n '/'$code'/p' File2 | cut -d ';' -f4
\#Join the data
output="$\{line\}|$\{data\}"
\#append it to the file
echo $output>>newFile1
i=\`expr $i \+ 1\`