I try to make a change in a file: find
Find a certain value and substitute it with another value in a different column using awk:.
Input (UiO-66Zr-EH.mof):
unit ntype qqatom
1 'Zr1' 0.0d0
vibration
0
improper
0
unit ntype qqatom
2 'H1' 0.0d0
vibration
0
improper
0
unit ntype qqatom
3 'C25' 0.0d0
vibration
0
improper
0
unit ntype qqatom
4 'O1' 0.0d0
Output (output):
unit ntype qqatom
1 'Zr1' 2.222d0
vibration
0
improper
0
unit ntype qqatom
2 'H1' 3.333d0
vibration
0
improper
0
unit ntype qqatom
3 'C25' 7.456d0
vibration
0
improper
0
unit ntype qqatom
4 'O1' 9.99d0
I've tried this command:
awk < UiO-66Zr-EH.mof '$2 ~ /Zr1/ {$3 ="2.222.d0"}1''$2 ~ /O1/ {$3 ="9.99d0"}1''$2 ~ /C25/ {$3 ="7.45d0"}1''$2 ~ /H1/ {$3 ="3.333d0"}1' > output
But it didn't function very well.
Can I do that with awk and keep, while also keeping the same formation also?