简体   繁体   中英

Make bash awk write in single line with separators

I'm a newbie to bash and i need to extract data from a file. I wrote it like this

    awk '/Iteration/''{print $3$4}''/TOTEN/''{print $5}''/energy without entropy/'
'{print $5 }''/energy without entropy/''{print $8 }' "OUTCAR.txt" > test.txt

the output is like this

1(1)
-298.23864042
-298.23333028
-298.23731288
1(2)
-1924.01607328
-1924.02845253
-1924.01916810

but i want every 4 results in a different column but single row. I tried awk -F '""' but it removes every result, leaving only empty lines edit: I want something like this

title1  title2  title3  title4
 1(1)  -298.23864042  -298.23333028  -298.23731288
 1(2)  -1924.01607328  -1924.02845253  -1924.01916810
 awk '/Iteration/{printf "%s%s\t", $3, $4} 
      /TOTEN/{printf "%s\t", $5}
      /energy without entropy/{printf "%s\t%s\n", $5, $8 }' OUTCAR.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM