简体   繁体   English

Linux awk命令隔离

[英]Linux awk command for isolation

If I had a file with hundreds of records, how do I isolate let's say the first 5 lines and display them using "awk"? 如果我有一个包含数百条记录的文件,该如何隔离前5行并使用“ awk”显示它们? I am trying to display a few lines from a file with several records of names, date etc. 我正在尝试从文件中显示几行,其中包含名称,日期等的多条记录。

Not sure what you like, since you have none input data or output example 由于您没有输入数据或输出示例,因此不确定您喜欢什么
If you like to print the 5 first line of a file using awk , you can do: 如果您想使用awk打印文件的第一行的第5行,则可以执行以下操作:

awk 'n {print;n--}' n=5 file

or just 要不就

awk 'NR<6' file

let's say the first 5 lines and display 假设前5行显示

Question is tagged for awk but head is what you need. 问题被标记为awkhead是您所需要的。 Use the right tool for the job. 使用正确的工具完成工作。 Although you can reinvent the wheel with awk 虽然您可以使用awk重新发明轮子

head -5 <file_name>

希望这行得通:

awk 'FNR<=5' file

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

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