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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to update one file based on data in another file ?

Status
Not open for further replies.

unixb1234

Programmer
Dec 21, 2008
8
US
Hello Everyone,

This is my question. I have two files and based on these files, I need to create a third file as mentioned below.

FILE1:
------
field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14
AA AAA Aaaaaaaaa,11111111,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111
AA AAA Aaaaaaaaa,11111111,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111
AA AAA Abbbbbbb,11111111,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111
BB BBB Axxxxxxxx,22222222,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111
BB BBB Axxxxxxxx,22222222,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111
BB BBB dddddddd,22222222,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111

I need to take the second column from this file_1 (which is a comma delimited file), here the values are : 11111111 and 22222222.

FILE2:
------
Here, I need to consider the last_column which is single character which is a middle initial.
11111111,last_name,first_name,D
22222222,last_name,first_name,

Finally, I need to add the new column to the file1 as field15 which consists of the values as "D and comma (D,)" for the records 11111111 and "null as ,," for the records 22222222 since this record
does not have any value in the last_column.

The output file should be like this:
------------------------------------
field1,field2,field3,field4,,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14,field15
AA AAA Aaaaaaaaa,11111111,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111,D,
AA AAA Aaaaaaaaa,11111111,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111,D,
AA AAA Abbbbbbb,11111111,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111,D,
BB BBB Axxxxxxxx,22222222,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111,,
BB BBB Axxxxxxxx,22222222,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111,,
BB BBB dddddddd,22222222,DDDDDDDDDD,last_name,first_name,F,19380101,EEE,254,20070116,20070116,,PHYSICIAN,H1111,,


Can this be done with awk ? and redireted to the outputfile ?

Thanks again, for all the help in advance and I appreciate all the help and thanskf or this website too.

Regards,
Bhanu
 
Hi Bhanu,

This question is very similar to your previous one, so you should be able to come up with a solution based on that one. Basically you need to read file 2 first, storing the middle initials in an array, and then read file 1, outputting the lines while looking up the value for field 15 in the array.

Annihilannic.
 
Hello again, Annihilannic, Thansk for ur response. Sorry for the delay in my reply..it was due to some problem with my account id in the web forum.

yes, I was able to modify and was able to get the results. Thansk again, very much.

Have a nice day :)
Regards,
Bhanu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top