繁体   English   中英

使用linux命令选择计数大于x小于y的行

[英]Select lines having count greater than x and less than y using linux command

我有以下文件:

1,A 
2,B
3,C
10000,D
20,E
4000,F

我想选择计数大于10且小于5000的行 输出应为EF。 用C ++或任何其他语言都是小菜一碟。 我真的很想知道如何使用linux命令。


我尝试了以下命令

awk -F ',' '{$1 >= 10 && $1 < 5000} { count++ } END { print $1,$2}' test.txt

但这仅是4000,F。

做就是了:

awk -F',' '$1 >= 10 && $1 < 5000' test.txt
  • 您将布尔值检查放入{....} ,并且根本不使用结果。 这没有任何意义。 您应该执行{if(...) ...}booleanExpression{do...}

  • 无用的count++

  • 您在END只有print语句,因此只打印了最后一行。

您的脚本实际上确实:

print the last line of the test.txt, no matter what it is.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM