'Using awk command to add an extra column

So yesterday I used sed command to read the n-th line of multiple files into a single output Read the n-th line of multiple files into a single output and I was able to generate a data.txt file which looks like this:

0 0 0 
-1.08051e-16 -1.73991e-16 -1.79157e-16 
-1.02169e-15 -1.19283e-15 5.92632e-16 
3.41114e-16 -1.02211e-15 3.19436e-15 
......

Note that they are all position data represent x, y and z axis. Now I just want to add one more column using awk command to represent time step which correspond the number of my dump file like 0 250 500...all the way to 40000.



Solution 1:[1]

Not sure if I understand your question correctly, but adding a column is pretty trivial in awk. You can do:

$ echo '0 0 0                                       
-1.08051e-16 -1.73991e-16 -1.79157e-16 
-1.02169e-15 -1.19283e-15 5.92632e-16                                             
3.41114e-16 -1.02211e-15 3.19436e-15 ' | awk 'BEGIN{val=0}{print $0,val;val+=250}'
0 0 0 0
-1.08051e-16 -1.73991e-16 -1.79157e-16  250
-1.02169e-15 -1.19283e-15 5.92632e-16  500
3.41114e-16 -1.02211e-15 3.19436e-15  750

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jaypal singh