This is my script
#!/bin/bash
for num in {1..100};
do
sed '$s/ 6.36535 23.3762512.09434/ 6.76889 21.76071 12.19032/' eq8_$num.gro | tee eq9_$num.gro
done
I want to replace " 6.36535 23.3762512.09434" to " 6.76889 21.76071 12.19032" (white space are important in this case, files have different number of lines, and this is the last line of each file).
Sed work only on the first file. Input example
eq8_1.gro
900 mgdg molecules in water t= 600000.00000 step= 400000000
177255
227BGL C529155 4.134 15.788 5.556
227BGL H529156 4.186 15.879 5.529
19144SOL OW73518 0.911 13.325 6.427
19144SOL HW173519 0.879 13.256 6.485
20389SOL OW77253 0.644 14.144 5.376
20389SOL HW177254 0.712 14.203 5.344
6.36535 23.3762512.09434
eq8_2.gro
900 mgdg molecules in water t= 600000.00000 step= 400000000
177255
19922SOL HW175853 4.186 14.169 5.941
19922SOL HW275854 4.071 14.076 5.973
19924SOL OW75858 1.466 20.721 5.803
19924SOL HW175859 1.489 20.642 5.852
6.36535 23.3762512.09434
Output examples
eq9_1.gro
900 mgdg molecules in water t= 600000.00000 step= 400000000
177255
227BGL C529155 4.134 15.788 5.556
227BGL H529156 4.186 15.879 5.529
19144SOL HW173519 0.879 13.256 6.485
19144SOL HW273520 1.007 13.318 6.431
20389SOL HW177254 0.712 14.203 5.344
20389SOL HW277255 0.577 14.201 5.413
6.76889 21.76071 12.19032
eq9_2.gro (last line dont change, why?)
900 mgdg molecules in water t= 600000.00000 step= 400000000
177255
19922SOL OW75852 4.097 14.168 5.977
19922SOL HW175853 4.186 14.169 5.941
19924SOL OW75858 1.466 20.721 5.803
19924SOL HW175859 1.489 20.642 5.852
6.36535 23.3762512.09434
I also try different method
#!/bin/bash
for num in {1..100};
do
sed -i '$s/ 6.36535 23.3762512.09434/ 6.76889 21.76071 12.19032/' eq8_$num.gro
done
It doesnt work too.
If you dont know how to do this in sed, maybe you know how to do this in awk?