I have written a bash script which searches all my directories and extracts some data that I need from files. Every thing works fine until I want to subtract the fist column of my files with a constant which is changing in each directory. The code looks like:
#!/bin/bash
ROOT=$(pwd)
#DIRS=$(find -name "*99")
DIRS[1]=99
DIRS[2]=199
DIRS[3]=299
DIRS[4]=399
DIRS[5]=499
DIRS[6]=599
DIRS[7]=699
DIRS[8]=799
DIRS[9]=899
DIRS[10]=999
for DIR in 1 2 3 4 5 6 7 8 9 10
do
dir=${DIRS[${DIR}]}
cd $dir
CDIR=$(pwd)
if [ $CDIR = $ROOT ]; then
continue
fi
#echo $CDIR
EFERMI=$(grep "E-fermi" OUTCAR | tail -n 1 | awk '{print $3}')
echo $EFERMI
# DOS
head -n 3007 DOSCAR | tail -n 3001 > DOS
cat DOS | awk '{print $1-$EFERMI , ($2+$3)/32}' > shifted_DOS_$dir
cat DOS | awk '{print $1 , ($2+$3)/32}' > nshifted_DOS_$dir
cp shifted_DOS_$dir $ROOT"/PLOTS"
cp nshifted_DOS_$dir $ROOT"/PLOTS"
cd $ROOT
done
The line "awk '{print $1-$EFERMI ..." is not working properly and it gives back wrong numbers for the first column. It is a constant shift which is different in each iteration, so it should follow the same logic as is mensioned in: how to subtract a constant number from a column but apparently it cannot distinguish $EFERMI value. Any idea how to do this without going to each directory and manually do the awk command separately?!
Thanks in advance