I have a series of directories, all with list.txt
in the same format, and I wish to put the results into a single file. I am looking to write a script that will iteratively move through each directory tree, extract a specific column from the list.txt
file without surrounding text using the grep/awk pipeline below and write the outputs of each to the same file.
grep 'bar[0-9]' file.txt | awk '{print $1}'
I have attempted the following but I am not sure exactly where my loops in the script are going wrong.
#!/bin/bash
##Extract ligands from toplist and concatenate to file
for i in /home/ubuntu/Project/working/library_*/Results/list.txt
do
grep 'bar[0-9]' i | awk '{print $1}' | cat ../output.txt i
done
The directory tree is as follows:
.
├── library_1-200
│ ├── Results
│ │ ├── complex
│ │ ├── sorted.txt
│ │ └── list.txt
│ ├── files
│ │ ├── output
│ │ └── txt
│ └── summary.txt
├── library_201-400
│ ├── Results
│ │ ├── complex
│ │ ├── sorted.txt
│ │ └── list.txt
│ ├── files
│ │ ├── output
│ │ └── txt
│ └── summary.txt
├── library_401-600
│ ├── Results
│ │ ├── complex
│ │ ├── sorted.txt
│ │ └── list.txt
│ ├── files
│ │ ├── output
│ │ └── txt
│ └── summary.txt
└── library_601-800
├── Results
│ ├── complex
│ ├── sorted.txt
│ └── list.txt
├── files
│ ├── output
│ └── txt
└── summary.txt
Sample of list.txt
, where I just want the Name
values put into output.txt
Name Score
bar65 -7.8
bar74 -7.5
bar14 -7.5
bar43 -7.4
bar94 -7.4
bar16 -7.4
bar12 -7.3
bar25 -7.3
bar65 -7.3
bar76 -7.3
bar24 -7.3
bar13 -7.3
bar58 -7.2
bar68 -7.2
bar28 -7.2
Solution was to put "$i" where I previously had just i and to modify to | cat >> ../output.txt
grep 'bar[0-9]' "$i" | awk '{print $1}' | cat > "$i"
, see https://unix.stackexchange.com/a/425801/70524 – muru May 27 '19 at 05:07... | cat > ../output.txt
, or without the unnecessarycat
, just> ../output.txt
. – RalfFriedl May 27 '19 at 05:27