检查特定列中的单词,检查该行其他列中的值,将该行剪切并粘贴到新的文本文件中

  • 本文关键字:文件 文本 其他 单词 bash awk sed
  • 更新时间 :
  • 英文 :


我的文本文件包含约20k行,如下所示:

文件_A:

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            

现在我需要检查第4列(第2行和第3行)中的POP,并检查最后一列(10)中的值是否超过特定阈值(例如5.00)。这些行-在本例中仅为第3行-需要从file_a中删除并复制到新的file_B。含义:

文件_A:

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   4125  W    PW   559      55.550  64.300  16.880  1.00  0.00

文件_B:

ATOM   3910  C2B POP   541      96.340  99.070  39.500  1.00  7.00

我不确定是使用sed、grep还是awk或任何与它们结合的东西:/到目前为止,我可以删除这些行并创建一个没有这些行的新文件。。。

awk '!/POP/' file_A > file_B

编辑:

以下内容适用于删除多个不同的单词吗?

for (( i= ; i<$numberoflipids ; i++ ))
do
        awk '$4~/"${nol[$i]}"/&&$NF>"$pr"{print >"patch_rmlipids.pdb";next}{print > "tmp"}' bilayer_CG_ordered.pdb && mv tmp patch.pdb
done

$nol是一个包含要删除的单词的数组,$pr是给定的阈值,.pdb是使用的文件

awk

awk '$4~/POP/&&$NF>5{print >"fileb";next}{print > "tmp"}' filea && mv tmp filea

$4~/POP/&&$NF>5  -Checks if fourth field contains POP and last field is more than five
{print >"fileb";next} -If they are writes the line to fileb and 
                        skips further statements
{print > "tmp"} -Only executed if first part fails, write to tmp file 
filea && mv tmp filea -The file used, if awk command succeeds then overwrite
                        it with tmp

最新更新