0
0
I have multiple tab delimited data files that are separated by month in the format jan06.txt, feb06.txt, ..., dec07.txt.
Within each file, it looks something like:
Header1 Header2 Header3 ...
Data1 Data2 Data3 ...
Data4 Data5 Data6 ...
... ... ...
What I want to do is to combine all all the data files into a single data file, with just a single header at the top, but also include a new data column that contains the month and year so I don't lose that information from the file name. So my new, single data file would contain:
Date Header1 Header2 Header3 ...
200601 Data1 Data2 Data3 ...
200602 Data4 Data5 Data6 ...
... ... ... ...
Where 200601 would refer to Jan 06, 200602 refer to Feb 06, etc.
I know if I do something like cat *.txt > data.txt, I could combine all my files. However, the two issues remain:
- I have a header in every file that would get concatenated, which I don't want.
- I would lose the month information that is stored in the file name.
I think I can do this with some combination of cat and sed, but I am not sure how to start.
(I'm not any good with script, I just wondered...) how do you want the data compressed (for lack of a better term) into a single data file? It appears to me that 200601,Header1 would have lots of data entries the old way and only 1 the new way. – Marcus Chan – 2013-02-01T23:16:50.217
@MarcusChan I added more to my question description above so hopefully that helps. But to explain more, for
jan06.txtI would want 200601 appended to a new data column on the left side for every row entry forjan01.txt. Forfeb06.txt, I would want 200602 appended to every row. I would then want all of those rows together in one data file with just a single header at the top. – user1027169 – 2013-02-01T23:46:51.340also asked on stackoverflow
– glenn jackman – 2013-02-02T03:05:47.110