我有以下文件:
1,A
2,B
3,C
10000,D
20,E
4000,F
Run Code Online (Sandbox Code Playgroud)
我想选择计数大于10且小于5000的行.输出应该是Ë和˚F.在C++或任何其他语言中都是小菜一碟.我真的想知道如何使用linux命令来完成它.
我尝试了以下命令
awk -F ',' '{$1 >= 10 && $1 < 5000} { count++ } END { print $1,$2}' test.txt
Run Code Online (Sandbox Code Playgroud)
但它只有givine 4000,F.
做就是了:
awk -F',' '$1 >= 10 && $1 < 5000' test.txt
Run Code Online (Sandbox Code Playgroud)
你把布尔检查放入{....},并且根本不使用结果.它没有任何意义.你应该做{if(...) ...}或者booleanExpression{do...}
无用 count++
print声明,END所以只打印出最后一行.你的脚本确实:
print the last line of the test.txt, no matter what it is.
Run Code Online (Sandbox Code Playgroud)