Good morning everyone.
Let me start by saying that this forum ROCKS!!! (You actually got me started using AWK (About 2 weeks now)).
I have a question and was not able to find the answer in the forum's archive.
I have file1 that looks like this:
000001 -- TAA -- 20061024 -- MOREDATA -- MOREDATA
000002 -- TCA -- 20051015 -- MOREDATA -- MOREDATA
000003 -- TAA -- 20061107 -- MOREDATA -- MOREDATA
etc....
Then file2 looks like this:
000001 -- TAA -- MOREDATA -- MOREDATA -- MOREDATA
000002 -- TCA -- MOREDATA -- MOREDATA -- MOREDATA
000003 -- TAA -- MOREDATA -- MOREDATA -- MOREDATA
000004 -- TAA -- MOREDATA -- MOREDATA -- MOREDATA
000006 -- TCA -- MOREDATA -- MOREDATA -- MOREDATA
etc....
I generate file2 every day (runs as a cronjob) so it contains the latest updates of data and adds new records as they get created.
I found file1 and noticed that it is consistent with my file2 as far as the first record is concerned and it also contains an accurate date of when the records are created but, it doesn't get updated everyday and it might have less records than file2 (file2 also contains more fields).
What I would like to do is get the date field from file1 and place it before the first "MOREDATA" field under file2 and if a record in file2 doesn't exist in file1, to enter the current date.
OR.... is there a way that as I generate file2, place the current date either in the middle or the end of every record so as the file starts archiving, all it has to do is enter the current date on the new records? I tried doing "date" under field3 but it enters the current date on all the fields as the report gets updated the next day and I need it to keep the date of when the records get first created.
Heres how I create file2:
awk -F, '
NR==FNR{a[$1]=$0;next}
{for(i in a)if($1~i){print a" -- "$3" -- "$4" -- "$5" -- "$7" -- "$10" -- "$14 ;next}}
' somedata.txt mydata.txt >>file2
I believe that once I get file2 with the date, I won't be needing file1 since I will be archiving file2 and then can compare the new file2 against the last archived file2 and get it going but I have the need of using file1 since it contains the accurate dates for every record (about 200) and I don't want to do it manually mainly for the room for error (yeah, it will take me too long as well).
Sorry this was long but I tried to be as clear as possible.
Please let me know if anyone has an answer to my question.
Thank you.
Let me start by saying that this forum ROCKS!!! (You actually got me started using AWK (About 2 weeks now)).
I have a question and was not able to find the answer in the forum's archive.
I have file1 that looks like this:
000001 -- TAA -- 20061024 -- MOREDATA -- MOREDATA
000002 -- TCA -- 20051015 -- MOREDATA -- MOREDATA
000003 -- TAA -- 20061107 -- MOREDATA -- MOREDATA
etc....
Then file2 looks like this:
000001 -- TAA -- MOREDATA -- MOREDATA -- MOREDATA
000002 -- TCA -- MOREDATA -- MOREDATA -- MOREDATA
000003 -- TAA -- MOREDATA -- MOREDATA -- MOREDATA
000004 -- TAA -- MOREDATA -- MOREDATA -- MOREDATA
000006 -- TCA -- MOREDATA -- MOREDATA -- MOREDATA
etc....
I generate file2 every day (runs as a cronjob) so it contains the latest updates of data and adds new records as they get created.
I found file1 and noticed that it is consistent with my file2 as far as the first record is concerned and it also contains an accurate date of when the records are created but, it doesn't get updated everyday and it might have less records than file2 (file2 also contains more fields).
What I would like to do is get the date field from file1 and place it before the first "MOREDATA" field under file2 and if a record in file2 doesn't exist in file1, to enter the current date.
OR.... is there a way that as I generate file2, place the current date either in the middle or the end of every record so as the file starts archiving, all it has to do is enter the current date on the new records? I tried doing "date" under field3 but it enters the current date on all the fields as the report gets updated the next day and I need it to keep the date of when the records get first created.
Heres how I create file2:
awk -F, '
NR==FNR{a[$1]=$0;next}
{for(i in a)if($1~i){print a" -- "$3" -- "$4" -- "$5" -- "$7" -- "$10" -- "$14 ;next}}
' somedata.txt mydata.txt >>file2
I believe that once I get file2 with the date, I won't be needing file1 since I will be archiving file2 and then can compare the new file2 against the last archived file2 and get it going but I have the need of using file1 since it contains the accurate dates for every record (about 200) and I don't want to do it manually mainly for the room for error (yeah, it will take me too long as well).
Sorry this was long but I tried to be as clear as possible.
Please let me know if anyone has an answer to my question.
Thank you.