I am trying to write a simple parser of configuration files, for example, there might be a file called INCAR:
NSW = 1000
POTIM = 1
TEBEG = 300
If I'd like to extract the value of POTIM, I could adopt awk to extrac the text between blanks and use the following script:
#!/bin/bash
vaspT ()
{
if [ -f INCAR ]; then
local potim=$(grep POTIM INCAR | awk '{print $3}');
else
local potim=1;
fi;
echo "# Time step: ${potim}" > .vasp_md.dat;
echo "# Step Temperature Total_energy E_pot E_kin" >> .vasp_md.dat;
}
vaspT
but if someone doesn't follow the rule of alignment, and use the configure file like:
NSW = 1000
POTIM=1
TEBEG=300
then, I have to use another delimiter.
My question is:
Is there a simple solution or an existing library (Python or Bash is acceptable)for this kind of job?