Originally Posted by
Arisinhell
Thanks for the fast reply!
Well to be clear i just need a script to (for example):
replace the 1st line of a file with "1" "space" "2"
replace the 11th line of the same file with "5" "space" "4"
..
replace the (1+10*i)th line of the same file with "1+i*4" "space" "2*(i+1)"
[...]
Those functions of i are just examples.
I'm not completely sure what you're after, but based on your examples you can try this:
Code:
awk ' /ITEM: TIMESTEP/ { flag=0 }
flag { print }
/ITEM: ATOMS type/ { flag=1; print 1+(i*4) " " 2*(i+1); i++ }
' velmps.dat
Output:
Code:
1 2
3.96234 2.15174 -3.08438
4.81728 -4.71916 2.30628
4.57479 2.70962 -0.816817
...
5 4
2.61854 3.17183 -2.45742
-0.322279 1.69319 2.70096
2.94569 -3.51979 0.784884
...
Going off the script in your first posting, you can insert the variables in awk like so:
Code:
Atoms=924
timestep=.0032
framestep=4
awk -v atoms="$Atoms" -v timest="$timestep" -v framest="$framestep" '
/ITEM: TIMESTEP/ { flag=0 }
flag { print $0 }
/ITEM: ATOMS type/ { flag=1; print (i+(i-1)*atoms) " " (i*framest) " " ((i-1)*timest); i++ }
' velmps.dat
If you need a floating point number with a given precision printed out, use printf, say for precision 5 it'd be:
Code:
printf "%.5f", (i+1)...
https://www.gnu.org/software/gawk/ma...ontrol-Letters.
Bookmarks