使用awk从文件中打印选定的行 [英] printing selected rows from a file using awk

查看:265
本文介绍了使用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

我要打印$ 1> 1000的所有行.

I want to print all the lines where $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?

推荐答案

您可以执行以下操作:

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

print $0将打印该行的所有内容

print $0 will print all the content of the line

如果要在第1000行/ROW之后打印该行的内容,则可以通过将$1替换为NR来执行相同的操作. NR代表行数.

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. NR represents the number of rows.

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

这篇关于使用awk从文件中打印选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆