kerry_13
kerry_13

Reputation: 289

Get data from multiple input file and write to another 1 file

I have a list of *.mto file containing my simulation result. They have the format as:

 vtpr             vtpf             temper           alter#            
  5.849e-01        3.034e-01        2.500e+01       1 

I want to get the value of vtpr and vtpf in each input files, then save them to a result file. Somebody suggest me use sed but i have no idea how can it works with multiple files. I use this code to print the 2nd line but in the result file, there's only the value of the final input files, not all the value because it's overwrited each time. can u give me some suggest ? thanks for help.

find . -name '*.mt0' -exec sed -n '2w result.txt' "{}"\;

Upvotes: 0

Views: 56

Answers (2)

ebohlman
ebohlman

Reputation: 15003

awk can do it all

awk 'FNR==2 {print $1, $2}' *.mt0 >output

Upvotes: 0

Prince John Wesley
Prince John Wesley

Reputation: 63698

Use cut with correct delimiter(default is TAB)

find . -name '*.mt0' -type f -exec sed -n '2{p;q}' {} \; | cut -f2 -d' ' > output

Upvotes: 1

Related Questions