I have a dataset with subjects of which the SUVr is calculated and put on the 3rd line of a txtfile, specific to each subject (so every subject has a different txtfile containing the SUVr). My question is: How can I get the 3rd line (which is the SUVr value) of every subjects' txtfile and place them in a new txtfile, so all the SUVRs of every subject are placed in one txtfile? I'm using the Linux terminal to do this. Thank you very much!
Asked
Active
Viewed 113 times
0
-
1Use ```grep``` for that lines you wanna ```>>``` to a file. No example provided - No exact answer possible – koyaanisqatsi May 05 '21 at 16:23
3 Answers
0
for file in $(find . -type f); do sed '3q;d' $file; done > output.txt
Some explanation about the command parts:
find . -type f
: list all files- If you need to filter by extension:
find . -type f -name "*.txt"
- If you need to filter by extension:
sed '3q;d' filename
: prints the 3rd line of the file- See more: Bash tool to get nth line from a file
> output.txt
: write tooutput.txt
(use>>
if you want to append)

Paulo Amaral
- 747
- 1
- 5
- 24
0
awk
works well for this also.
awk '3 == FNR { print $0; }' /path/to/$files.* >found
FNR is File Number of Records, so it grabs the 3rd line from each file without executing over and over, or needing a find
, etc.

Paul Hodges
- 13,382
- 1
- 17
- 36