Changing one number in all files using awk

Hi

I want to change the number 70 mentioned in my file to 76 by using awk. I know how to change all same digits but not one particular number.

I have 29 files almost similar to this. One of my files looks like

#Input file for 200K NPT molecular dynamics of final 70%XL made from 58.5% X-Linked EPON:DETDA hardener at 63.6117 Angs final box size (with 100% VDW and interchanged columns)

units real
dimension 3
boundary p p p

atom_style molecular

neighbor 4.0 bin
neigh_modify every 1 delay 0 check yes page 1000000 one 100000

echo screen

#OPLS potentials

bond_style harmonic
angle_style harmonic
dihedral_style opls

pair_style lj/cut/opt 10.0
pair_modify mix arithmetic

read_data DataFile_432isto216_70XLfrom58point5XL_7thmin.xyz

#dynamics commands
#initial velocities

compute 1 all temp
compute 2 all pressure 1
compute 3 all pe
velocity all create 200.0 200.0

#fixes

fix 1 all npt 200.0 200.0 10.0 xyz 1.0 1.0 10.0 drag 2.0

dump EPONDETDA all xyz 100000.0 epon432isto216_70XLfrom58point5XL_dumpNPT_200Kdynamics.xyz

#run

timestep 0.4
thermo 100
thermo_modify lost warn
thermo_style custom step temp pe ke etotal evdwl epair ebond eangle edihed emol press vol

run 500000

Any suggestions? :confused:

Hi,

Why don't you try to use sed instead...., like this.

sed �s/70XL/76XL/g� input_file > output_file

BTW - If you have too many files, you can process them with a script using a "for i in " for example.

Thanks,

Marco,

1 Like
ruby -i.bak -ne 'print if gsub(/70XL/,"76XL")' file

by awk, there is sub or gsub function to do the same job.

awk '{gsub(/70XL/,"76XL")}1' file