AWK或Perl单行打印行,如果第二个字段是超过7个字符长 [英] awk or perl one-liner to print line if second field is longer than 7 chars

查看:125
本文介绍了AWK或Perl单行打印行,如果第二个字段是超过7个字符长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1000行的文件,每行有2个字,用空格隔开。如何打印每行只有最后一个字长度大于7个字符更大?我可以用awk RLENGTH?有没有在Perl一个简单的方法?

I have a file of 1000 lines, each line has 2 words, separated by a space. How can I print each line only if the last word length is greater than 7 chars? Can I use awk RLENGTH? is there an easy way in perl?

推荐答案

@OP,当你调用匹配()函数awk的RLENGTH使用。相反,使用长度()函数来检查字符长度

@OP, awk's RLENGTH is used when you call match() function. Instead, use the length() function to check for length of characters

awk 'length($2)>7' file

如果你正在使用bash,外壳的解决方案

if you are using bash, a shell solution

while read -r a b
do
  if [ "${#b}" -gt 7 ];then
    echo $a $b
  fi
done <"file"

这篇关于AWK或Perl单行打印行,如果第二个字段是超过7个字符长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆