Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare 2 files and insert column in new file

Status
Not open for further replies.

donet

Programmer
Apr 12, 2006
1
GB
I would like to read a file from the orignal directory and one from the new directory. The new file is a copy of the orig but is missing data from column 1-5 and is in lower case. I would like to add the missing data from 1-5(orig file) by comparing the lines in each file and if the match put the data from 1-5 in the new file.
I would like to read a file from the original and macth it with the new file and process the files.


orig file


* CR#: DATE: WHO: DESCRIPTION OF CHANGE:
* 999999 01/01/05 FRED JACKSON
A12345* 123454 01/01/05 FRED JACKSON
B67457* 123454 01/01/05 FRED JACKSON
C12345* 123456 01/01/05 FRED JACKSON
*
*----------------------------------------------*

new file
* cr#: date: who: description of change:
* 999999 01/01/05 fred jackson
* 123454 01/01/05 fred jackson
* 123454 01/01/05 fred jackson
* 123456 01/01/05 fred jackson
lc* * 124446 04/02/05 changed to lc
*---------------------------------------------------*

after file processing

*----------------------------------------------*
* cr#: date: who: description of change:
* 999999 01/01/05 fred jackson
A12345* 123454 01/01/05 fred jackson
B67457* 123454 01/01/05 fred jackson
C12345* 123456 01/01/05 fred jackson
lc* * 124446 04/02/05 changed to lc
*----------------------------------------------*

I tried the following code but it shifts everything to the left. I also had to change the case in the original file.

awk 'BEGIN{FS == ""}NR==FNR{a[$2,$3,$4]=$1;next}a[$2,$3,$4]!=""{$1=a[$2,$3,$4]}1' orig new > output


Thanks,
 
If you have UNIX or a clone, consider using the join command. I think its more likely to do what you want
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top