且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用awk在match()函数中使用变量来定义范围"r(n,)"

更新时间:2023-02-18 13:00:47

match将变量RLENGTH设置为匹配的子字符串的长度,并加以利用.另外,您不需要为此使用多字符RS.

match sets variable RLENGTH to the matched substring's length, make use of it. Also, you don't need a multi-char RS for this.

awk -v start_g="$start_gaps" -v end_g="$end_gaps" '
/^>/ { hdr=$0; next }
match($0,/^-*/) && RLENGTH<=start_g && match($0,/-*$/) && RLENGTH<=end_g { print hdr; print }
' file