更新时间:2023-12-05 14:57:22
没有循环和复杂性在各种需要awk的匹配(和打印):
No looping or complexity needed for awk to match (and print) in a range:
awk 'NR>start && NR<end && /pattern/'
一个有点棘手文件B的内容转换成正确的 AWK
的条件,但这是:
A bit trickier to convert file B content to the right awk
condition, but this does it:
echo "($(awk 'NR==1{r1=$1;next}
NR>2{printf"||"}
{printf"(NR>%d&&NR<%d)",r1,$1;r1=$1}
END{if(NR<2)printf"0"}' B))&&/yourpattern/"|
awk -f- A
也许稍微简单的将是pre-过滤器使用SED的范围,然后用grep的格局:
Perhaps slightly simpler would be to pre-filter the ranges using sed, and then grep for the pattern:
awk 'NR==1{r1=$1;next}
$1>r1+1{printf"%d,%dp\n",r1+1,$1-1;r1=$1}' B|
sed -nf- A|
grep 'yourpattern'