I also have another single file called file1.txt, that has a single column with 19 rows in it.
vi file1.txt
A
D
F
G
E
T
G
E
W
T
T
W
I would like to get a third file by greping contents from each of the above files in the following manner.
for example, if we take the file B_A17_A17_1T.txt, I would like to grep part of the file name, A17_1T and print it 12 times as the first column. Then print the content of file1.txt as the second column and then print or grep the third column in the file B_A17_A17_1T.txt. I don't need the headers of the file B_A17_A17_1T.txt.
The sample output file will be a tab delimited file:
A17_1T A 0
A17_1T D 1
A17_1T F 6
A17_1T G 0
A17_1T E 0
A17_1T T 0
A17_1T G 1
A17_1T E 0
A17_1T W 0
A17_1T T 1
A17_1T T 1
A17_1T W 0
It would be great if I could do this merging and greping of contents for atleast one file and I could repeat the rest. Is awk best for this?
Thanks vgersh 99. It worked fine. but I would like only part of the file name as the first column. A17_1T. At the present, the awk code will give almost all the file name.
Thanks Chubler_XL. If the file name, B_A17_A17_1T.txt has more character, where do I change the code?
for example instead of B_A17_A17_1T.txt if the file name was Bvtr_A17_A17_1T.txt. Please let me know where to chnage the code. I believe it is in this part of the code
Yes, you are correct the substr statement you quoted takes 3 characters starting at position 3 of the filename and substr(FILENAME,10,3 takes 3 characters starting from position 10. As the two substr are next to each other they are joined together.
I'm not sure this approach is going to work out for you, the approach taken by the other solutions posted here involves matching on the Underscore(_) character and might be more flexable depending on your actual filenames.