Ralnor
Ralnor

Reputation: 43

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

Upvotes: 0

Views: 90

Answers (1)

William Pursell
William Pursell

Reputation: 212514

 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

Upvotes: 2

Related Questions