24小时热门版块排行榜    

查看: 1697  |  回复: 5

小小鑫000

铁虫 (小有名气)

[求助] 我自己写了个vasp的shell脚本,高手帮我看看哪错了?

各位高手,大家好:
我想写一个脚本,目的是把TOTAL FORCE下的力的数据呈现到comment文件中。也就是我想把OUTCAR里的一下部分通过脚本写到comment文件中。如下:
POSITION                                       TOTAL-FORCE (eV/Angst)
-----------------------------------------------------------------------------------
      0.00000      0.00000      4.05312         0.000010     -0.000006     -0.005155
      0.00000      0.00000     10.13242         0.000022     -0.000013     -0.030471
      1.24096      0.71646      2.02643        -0.000046      0.000027     -0.050123
      1.24096      0.71646      8.10599        -0.000039      0.000023      0.059639
     -0.00001      1.43293      0.00000        -0.000014      0.000008      0.029145
     -0.00001      1.43293      6.07955         0.000067     -0.000039     -0.003035
我自己写的脚本如下:
#!/bin/sh
rm WAVECAR -rf
source /opt/openmpi/openmpi-intel.sh
source /etc/profile
mpirun -np 16 -machinefile ma vasp
E=`grep -A 7 TOTAL OUTCAR | tail -6 | awk   '{printf   "%12.6f \n"}'`
echo $E >>comment

其中source /opt/openmpi/openmpi-intel.sh
source /etc/profile
mpirun -np 16 -machinefile ma vasp
这三行是我这个机器的运行指令,这个绝对没错,但这之外的就是我瞎写的了。
最后的结果就是comment文件空白,机器出现如下提示:
fatal: not enough arguments to satisfy format string
        `%12.6f
'
             ^ ran out for this one
求各位前辈帮我改正一下,谢谢!
回复此楼
好好研究,天天向上!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

jpchou

专家顾问 (著名写手)

★ ★
identation: 金币+2, 谢谢交流 2014-02-25 15:53:44
E=`grep -A 7 TOTAL OUTCAR | tail -6 | awk   '{printf   "%12.6f \n"}'`
=>
E=`grep -A 7 TOTAL OUTCAR | tail -6 | awk   '{printf   "%12.6f %12.6f %12.6f \n",$4,$5,$6}'`
2楼2014-02-21 22:59:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

小小鑫000

铁虫 (小有名气)

引用回帖:
2楼: Originally posted by jpchou at 2014-02-21 22:59:53
E=`grep -A 7 TOTAL OUTCAR | tail -6 | awk   '{printf   "%12.6f \n"}'`
=>
E=`grep -A 7 TOTAL OUTCAR | tail -6 | awk   '{printf   "%12.6f %12.6f %12.6f \n",$4,$5,$6}'`

前辈,谢谢您的指导,最后comment的结果如下呈现:
0.000010 -0.000006 -0.005155 0.000022 -0.000013 -0.030471 -0.000046 0.000027 -0.050123 -0.000039 0.000023 0.059639 -0.000014 0.000008 0.029145 0.000067 -0.000039 -0.003035
但我又想让它完全呈现下面的全部内容及写法和格式:
POSITION                                       TOTAL-FORCE (eV/Angst)
-----------------------------------------------------------------------------------
      0.00000      0.00000      4.05312         0.000010     -0.000006     -0.005155
      0.00000      0.00000     10.13242         0.000022     -0.000013     -0.030471
      1.24096      0.71646      2.02643        -0.000046      0.000027     -0.050123
      1.24096      0.71646      8.10599        -0.000039      0.000023      0.059639
     -0.00001      1.43293      0.00000        -0.000014      0.000008      0.029145
     -0.00001      1.43293      6.07955         0.000067     -0.000039     -0.003035
不要像0.000010 -0.000006 -0.005155 0.000022 -0.000013 -0.030471 -0.000046 0.000027 -0.050123 -0.000039 0.000023 0.059639 -0.000014 0.000008 0.029145 0.000067 -0.000039 -0.003035
这样杂乱,并且有POSITION                                       TOTAL-FORCE (eV/Angst) 这一行也要加上啊!前辈该怎吗改?
好好研究,天天向上!
3楼2014-02-22 11:49:34
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

jpchou

专家顾问 (著名写手)

★ ★
identation: 金币+2, 谢谢交流 2014-02-25 15:53:51
#!/bin/sh
rm WAVECAR -rf
source /opt/openmpi/openmpi-intel.sh
source /etc/profile
mpirun -np 16 -machinefile ma vasp
grep -A 1 TOTAL OUTCAR > comment
grep -A 7 TOTAL OUTCAR | tail -6 | \
   awk   '{printf   "%12.6f %12.6f %12.6f %12.6f %12.6f %12.6f \n",$1,$2,$3,$4,$5,$6}'  \
   >> comment
4楼2014-02-23 18:42:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

小小鑫000

铁虫 (小有名气)

引用回帖:
4楼: Originally posted by jpchou at 2014-02-23 18:42:32
#!/bin/sh
rm WAVECAR -rf
source /opt/openmpi/openmpi-intel.sh
source /etc/profile
mpirun -np 16 -machinefile ma vasp
grep -A 1 TOTAL OUTCAR > comment
grep -A 7 TOTAL OUTCAR | tail -6 | \
   ...

前辈,这样写的话还对吗?
grep TOTAL OUTCAR |tail -1 >>comment
grep -A 7 TOTAL OUTCAR | tail -6 | \
   awk   '{printf   "%12.6f %12.6f %12.6f %12.6f %12.6f %12.6f \n",$1,$2,$3,$4,$5,$6}'  \
   >> comment
或grep -A 1 TOTAL OUTCAR |tail -1 >>comment
grep -A 7 TOTAL OUTCAR | tail -6 | \
   awk   '{printf   "%12.6f %12.6f %12.6f %12.6f %12.6f %12.6f \n",$1,$2,$3,$4,$5,$6}'  \
   >> comment
哪?
好好研究,天天向上!
5楼2014-02-25 12:43:20
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

jpchou

专家顾问 (著名写手)

★ ★
identation: 金币+2, 谢谢交流 2014-02-25 15:53:59
引用回帖:
5楼: Originally posted by 小小鑫000 at 2014-02-25 12:43:20
前辈,这样写的话还对吗?
grep TOTAL OUTCAR |tail -1 >>comment
grep -A 7 TOTAL OUTCAR | tail -6 | \
   awk   '{printf   "%12.6f %12.6f %12.6f %12.6f %12.6f %12.6f \n",$1,$2,$3,$4,$ ...

grep TOTAL OUTCAR |tail -1 >>comment
對~ TOTAL 在 OUTCAR 內很多次
應該要加 tail 沒錯

tail 我比較喜歡寫成 tail -n 1
因為 tail -1 不是每一台機器的 tail 都可以這樣寫
所以完整寫法應該是  grep TOTAL OUTCAR | tail -n 1 >> comment
6楼2014-02-25 14:14:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 小小鑫000 的主题更新
信息提示
请填处理意见