嵌套的awk命令? [英] nested awk commands?
问题描述
我有以下两个代码:
nut=`awk "/$1/{getline; print}" ids_lengths.txt`
和
grep -v '#' neco.txt |
grep -v 'seq-name' |
grep -E '(\S+\s+){13}\bAC(.)+CA\b' |
awk '$6 >= 49 { print }' |
awk '$6 <= 180 { print }' |
awk '$4 > 1 { print }' |
awk '$5 < $nut { print }' |
wc -l
我希望我的脚本在此处替换"nut":
I would like my script to replace "nut" at this place:
awk '$4 < $nut { print }'
,其中包含从此返回的数字:
with the number returned from this:
nut=`awk "/$1/{getline; print}" ids_lengths.txt`
但是,上面代码中的$ 1应该不是ids_lengths.txt中的列,而是neco.txt中的第一列! (就像我在主代码中使用$ 6和$ 4一样.)
However, $1 in code just above should represent not column from ids_lengths.txt, but first column from neco.txt! (similiarly as I use $6 and $4 in main code).
将非常感谢您提供帮助来解决这些嵌套的awks:-)
A help how to solve these nested awks will definitely be appreciated:-)
我的输入文件(neco.txt)的行如下所示:
edit: Line of my input file (neco.txt) looks like this:
FZWTUY402JKYFZ 2 100.000 3 11 9 4.500 7 0 0 0 . TG TGTGTGTGT
最大的问题是,在第一列(例如FZWTUY402JKYFZ)中进行搜索时,我想过滤那些第五列中的行号小于number的行,这些行是从另一个文件(ids_lengths.txt)获得的.这就是为什么我在草稿脚本中放入"nut"变量的原因:-)
The biggest problem is that I want to filter those lines that have in the fifth column number less than number, which I get from another file (ids_lengths.txt), when searching with first column (e.g. FZWTUY402JKYFZ). That's why I put "nut" variable in my draft script :-)
ids_lengths.txt看起来像这样:
ids_lengths.txt looks like this:
>FZWTUY402JKYFZ
153
>FZWTUY402JXI9S
42
>FZWTUY402JMZO4
158
推荐答案
您可以将两个grep -v
操作和四个连续的awk
操作组合在一起.这可为您带来有用的经济效益,而无需完全重写所有内容:
You can combine the two grep -v
operations and the four consecutive awk
operations into one of each. This gives you useful economy without completely rewriting everything:
nut=`awk "/$1/{getline; print}" ids_lengths.txt`
grep -E -v '#|seq-name' neco.txt |
grep -E '(\S+\s+){13}\bAC(.)+CA\b' |
awk -vnut="$nut" '$6 >= 49 && $6 <= 180 && $4 > 1 && $5 < nut { print }' |
wc -l
我不会费心让单个awk
脚本确定nut
的值并进行基于值的过滤.可以做到,但是却不必要地使事情复杂化-除非您可以证明整个事情是生产系统性能的瓶颈,否则这种情况下您会更加努力地工作(尽管在这种情况下我可能会使用Perl;它会只需一个命令就可以完成全部任务.)
I would not bother to make a single awk
script determine the value of nut
and do the value-based filtering. It can be done, but it complicates things unnecessarily — unless you can demonstrate that the whole thing is a bottleneck for the performance of the production system, in which case you do work harder (though I'd probably use Perl in that case; it can do the whole lot in one command).
这篇关于嵌套的awk命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!