簡體   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