【发布时间】:2014-10-27 20:09:36
【问题描述】:
到目前为止,我有一个相当长的脚本,但无法真正让这个 awk 命令工作。我有这个 for 循环:
echo "$numberoflipids" # 1
for (( i=0 ; i<$numberoflipids ; i++ ))
do
echo "${nol[$i]}" # POPC
echo "$pr" # 5
awk -v lipid="${nol[$i]}" threshold="$pr" '$4~/lipid/&&$NF>threshold{print >"filec";next}{print > "tmp"}' filea && mv tmp fileb
## Also tried this:
# awk '$4~/"'${nol[$i]}'"/&&$NF>"'$pr'"{print >"patch_rmlipids.pdb";next}{print > "tmp"}' bilayer_CG_ordered.pdb && mv tmp patch.pdb
## And this works... (giving the exact values)
# awk '$4~/"POPC"/&&$NF>5{print >"patch_rmlipids.pdb";next}{print > "tmp"}' bilayer_CG_ordered.pdb && mv tmp patch.pdb
done
第三个 awk 命令对我来说工作得很好...它在我的 filea 的第 4 列中搜索 POPC,将最后一列中超过 5 的行复制到 filec 并将剩余的行复制到 fileb .
我希望你们中的某个人能抽出时间阅读代码,也许能给我一些建议,因为我没有给 awk 这些变量。
PS:我的文件如下所示:
ATOM 624 SC1 SER 288 54.730 23.870 56.950 1.00 0.00
ATOM 3199 NC3 POP 487 50.780 27.750 27.500 1.00 3.18
ATOM 3910 C2B POP 541 96.340 99.070 39.500 1.00 7.00
ATOM 4125 W PW 559 55.550 64.300 16.880 1.00 0.00
(关于 awk 命令的旧帖子:bash - check for word in specific column, check value in other column of this line, cut and paste the line to new text file)
【问题讨论】:
标签: awk