I am trying to do the following:
- Loop through a list of files
- Edit each file and output a "trimmed" file
- Horizontally join each trimmed file in turn to a pre-made master file
I have steps 1 & 2 working, but can't get 3 to work.
Example
MASTER FILE:
Col1 Col2
A 1
B 1
C 2
TRIMMED FILE for file S1:
S1.Col3 S1.Col4
0 1
1 1
1 1
OUTPUT I WANT after S1 & S2 have been joined to MASTER:
Col1 Col2 S1.Col3 S1.Col4 S2.Col3 S2.Col4
A 1 0 1 0 1
B 1 1 1 1 0
C 2 1 1 0 0
After each loop, I've tried running something like:
paste MASTER.txt S1.txt > MASTER.txt
However, instead of the above, I get a file with only the last S file's data. I tried running this without outputting and outside of the loop, everything works fine. Thanks in advance for any answers.
For completion, here is a very simplified breakdown of my for loop.
for FILE in FILELIST
do
cut -f4,6 $FILE > ${FILE}_trimmed.txt
paste MASTER.txt ${FILE}_trimmed.txt > MASTER.txt
done