What does awk under linux mean?

王林
Release: 2020-06-29 11:42:18
Original
5337 people have browsed it

linux下的awk是行处理器,通常用来格式化文本信息。awk在处理庞大文件时不会出现内存溢出的问题。awk命令格式:【awk [-F|-f|-v] ‘BEGIN{} //{command1; command2} END{}' file】。

What does awk under linux mean?

awk介绍

(推荐教程:linux教程

awk是行处理器,相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息。

awk处理过程:依次对每一行进行处理,然后输出。

awk命令形式:

awk [-F|-f|-v] ‘BEGIN{} //{command1; command2} END{}’ file
Copy after login

参数介绍:

  • -F 指定分隔符

  • -f 调用脚本

  • -v 定义变量

  • ' ' 引用代码块

  • BEGIN 初始化代码块,在对每一行进行处理之前,初始化代码,主要是引用全局变量,设置FS分隔符

  • // 匹配代码块,可以是字符串或正则表达式

  • {} 命令代码块,包含一条或多条命令

  • END 结尾代码块,在对每一行进行处理之后再执行的代码块,主要是进行最终计算或输出结尾摘要信息

我们来看一下几个应用:

awk -F: '{print NF}' /etc/passwd //输出文件每行有多少字段 awk -F: '{print $1,$2,$3,$4,$5}' /etc/passwd //输出前5个字段 awk -F: '{print $1,$2,$3,$4,$5}' OFS='\t' /etc/passwd //输出前5个字段并使用制表符分隔输出 awk -F: '{print NR,$1,$2,$3,$4,$5}' OFS='\t' /etc/passwd //制表符分隔输出前5个字段,并打印行号
Copy after login

The above is the detailed content of What does awk under linux mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!