特定行的AWK打印命令 [英] AWK print command for specific rows

查看:119
本文介绍了特定行的AWK打印命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的文件中有数百万条记录,我需要做的是打印1396至1400列以显示特定的行数,并且如果可以在excel或记事本中获取它.

I have millions of records in my file, what i need to do is print columns 1396 to 1400 for specific number of rows, and if i can get this in excel or notepad.

尝试过此命令

awk {print $1396,$1397,$1398,$1399,$1400}' file_name

但这正在每一行运行.

推荐答案

您需要一个条件来指定将操作应用于哪些行:

You need a condition to specify which rows to apply the action to:

awk '<<condition goes here>> {print $1396,$1397,$1398,$1399,$1400}' file_name

例如,仅对第50到100行执行此操作:

For example, to do this only for rows 50 to 100:

awk 'NR >= 50 && NR <= 100 {print $1396,$1397,$1398,$1399,$1400}' file_name

(根据您要执行的操作,您还可以选择比这复杂得多的选择模式.)

(Depending on what you want to do, you can also have much more complicated selection patterns than this.)

这是一个更简单的测试示例:

Here's a simpler example for testing:

awk 'NR >= 3 && NR <= 5 {print $2, $3}'

如果我在包含以下内容的输入文件上运行

If I run this on an input file containing

1 2 3 4
2 3 4 5
3 a b 6
4 c d 7
5 e f 8
6 7 8 9

我得到了输出

a b
c d
e f

这篇关于特定行的AWK打印命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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