I have two related sets of files that I need to search. Please note that the dashes are not part of the file they just separate the file names
from the contents
Set 1 has the following fields date, record number, name
set1_2009-05-20.txt << file name
-------------------
2009-05-20~1~Name1
2009-05-20~2~Name2
2009-05-20~3~Name1
2009-05-20~4~Name3
2009-05-20~17~Name3
set1_2009-05-14.txt
--------------------
2009-05-21~14~Name4
2009-05-21~15~Name1
2009-05-21~17~Name1
2009-05-21~18~Name4
2009-05-21~21~Name4
Set 2 has the following format record number, value
set2_2009-05-20.txt << file name
-------------------
1~der
1~tyu
2~rxs
2~43w
3~5sd
4~rte
17~56g
set2_2009-05-14.txt
--------------------
14~res
15~oph
15~fgh
17~def
18~aba
21~ghc
At the end of my search I am supposed to come up with two files set1_out.txt and set2_out.txt. From set 1, (easy part) I need all records with Name 1
this I get by running the simple awk command
this gives me
set1_out.txt
-----------------------------
2009-05-20~1~Name1
2009-05-20~3~Name1
2009-05-21~15~Name1
2009-05-21~17~Name1
getting set2_out.txt is a little trickier. For every record number, date pair in set1_out.txt I have to find the corresponding record and file
in set 2 and end up with a file with the structure "record number~value~date". With date being the date stamp on the file being processed(which is also the date in the matching line of set1_out.txt). e.g
set2_out.txt
----------------
1~der~2009-05-20
1~tyu~2009-05-20
3~5sd~2009-05-20
15~oph~2009-05-21
15~fgh~2009-05-21
17~def~2009-05-21
With my limited shell scripting skills I have no idea where to begin on the second part. I hope this is the right forum for this.
Thanks in advance for your help
from the contents
Set 1 has the following fields date, record number, name
set1_2009-05-20.txt << file name
-------------------
2009-05-20~1~Name1
2009-05-20~2~Name2
2009-05-20~3~Name1
2009-05-20~4~Name3
2009-05-20~17~Name3
set1_2009-05-14.txt
--------------------
2009-05-21~14~Name4
2009-05-21~15~Name1
2009-05-21~17~Name1
2009-05-21~18~Name4
2009-05-21~21~Name4
Set 2 has the following format record number, value
set2_2009-05-20.txt << file name
-------------------
1~der
1~tyu
2~rxs
2~43w
3~5sd
4~rte
17~56g
set2_2009-05-14.txt
--------------------
14~res
15~oph
15~fgh
17~def
18~aba
21~ghc
At the end of my search I am supposed to come up with two files set1_out.txt and set2_out.txt. From set 1, (easy part) I need all records with Name 1
this I get by running the simple awk command
Code:
awk -F~ '{if (tolower($3)=="name1") print $0}' set1*.txt >set1_out.txt
this gives me
set1_out.txt
-----------------------------
2009-05-20~1~Name1
2009-05-20~3~Name1
2009-05-21~15~Name1
2009-05-21~17~Name1
getting set2_out.txt is a little trickier. For every record number, date pair in set1_out.txt I have to find the corresponding record and file
in set 2 and end up with a file with the structure "record number~value~date". With date being the date stamp on the file being processed(which is also the date in the matching line of set1_out.txt). e.g
set2_out.txt
----------------
1~der~2009-05-20
1~tyu~2009-05-20
3~5sd~2009-05-20
15~oph~2009-05-21
15~fgh~2009-05-21
17~def~2009-05-21
With my limited shell scripting skills I have no idea where to begin on the second part. I hope this is the right forum for this.
Thanks in advance for your help