简体   繁体   English

使用awk从文件中打印选定的行

[英]printing selected rows from a file using awk

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 {$1 > 1000} {print "  " $1 "  "$2 "  "$3}' graph_data_tmp.txt

This doesn't seem to give the output that I am expecting.What am I doing wrong? 这似乎没有提供我期望的输出。我在做什么错?

You can do this : 你可以这样做 :

awk '$1>1000 {print $0}' graph_data_tmp.txt

print $0 will 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 $1 with NR . 如果要在第1000行/ ROW之后打印该行的内容,则可以通过将$1替换$1 NR NR represents the number of rows. NR代表行数。

awk 'NR>1000 {print $0}' graph_data_tmp.txt

所有你需要的是:

awk '$1>1000' file

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

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