i will like to modified some files with the extension .gjf . All this files have in first line this #P PM3 Opt and i want to change that to this :
%nproc=2
%chk=filename.chk
#p B3LYP /6-31G** opt
in order to do that i have try to do a script with the sed command but i really don't know how to insert %nproc=2 in line N�1, %chk=filename.chk in line N�2 and #p B3LYP /6-31G** opt in line N�3 . The script that i have wrote is
for x in $(ls *.gjf);
do n=$(echo $x | cut -d. -f1);
echo " sed -i 's/#P PM3 Opt/nproc=2 %chk=$n.chk #p B3LYP \/6-31G** opt/g' $n.gjf"
done
but this change the text #P PM3 Opt by nproc=2 %chk=$n.chk #p B3LYP / 6-31G** opt all this text in the first line.
i will be very grateful if some one of the forum can help me in solve this problem.
#!/bin/sh
for x in *gjf; do
n=${x%.*}
sed -i0 's/#P PM3 Opt/nproc=2\n%chk='"$n"'.chk\n#p B3LYP \/6-31G** opt/' "$x"
done
Putting "$n" out of sed script seems to do the trick
[Wont edit this] I added 0 after -i in sed command so all gjf files will be backed up as .gjf0, in case something goes wrong