bash 使用 awk 从文件中打印选定的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18478111/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
printing selected rows from a file using awk
提问by liv2hak
I have a text file with data in the following format.
我有一个包含以下格式数据的文本文件。
1 0 0
2 512 6
3 992 12
4 1536 18
5 2016 24
6 2560 29
7 3040 35
8 3552 41
9 4064 47
10 4576 53
11 5088 59
12 5600 65
13 6080 71
14 6592 77
15 7104 83
I want to print all the lines where $1 > 1000.
我想打印 $1 > 1000 的所有行。
awk 'BEGIN { > 1000} {print " " " " " "}' graph_data_tmp.txt
This doesn't seem to give the output that I am expecting.What am I doing wrong?
这似乎没有给出我期望的输出。我做错了什么?
回答by iamauser
You can do this :
你可以这样做 :
awk '>1000 {print awk 'NR>1000 {print awk '>1000' file
}' graph_data_tmp.txt
}' graph_data_tmp.txt
print $0will print all the content of the line
print $0将打印该行的所有内容
If you want to print the content of the line after the 1000th line/ROW, then you could do the same by replacing $1with NR. NR represents the number of rows.
如果要打印第 1000 行/ROW 之后的行的内容,则可以通过替换$1为NR. NR 代表行数。
回答by Ed Morton
All you need is:
所有你需要的是:
##代码##
