awk用法

本文详细介绍了文本过滤器grep、流编辑器sed和报告生成器awk的使用方法,通过实例展示了如何进行文本过滤、格式化和数据分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

grep:文本过滤器,
grep "pattern" input_file ....

sed: 流编辑器;
sed "command/PATTERD/"

awk:报告生成器。能够将输入的信息格式化之后显示;包括nawk版本,gawk版本

用法:

  awk [option] 'script' file1 file2, ...
  awk [option] 'PATTERN {action}' file1, file2. ...
    print, printf

 1 root@ubuntu-ceph-07:~# echo  "this is a test" >>test.txt
 2 root@ubuntu-ceph-07:~# awk '{print $0}' test.txt
 3 this is a test
 4 root@ubuntu-ceph-07:~# awk '{print $1}' test.txt
 5 this
 6 root@ubuntu-ceph-07:~# awk '{print $2}' test.txt
 7 is
 8 root@ubuntu-ceph-07:~# awk '{print $1$2}' test.txt
 9 thisis
10 root@ubuntu-ceph-07:~# awk 'BEGIN{OFS="#"}{print $1,$2}' test.txt
11 this#is
12 root@ubuntu-ceph-07:~# awk '{print $1,$2}' test.txt
13 this is
14 root@ubuntu-ceph-07:~# awk 'BEGIN{OFS=":"}{print $1, $2, $3, $4}' test.txt
15 this:is:a:test
16 root@ubuntu-ceph-07:~# awk 'BEGIN{OFS=":"}{print $1, $2, "AAAAAAA",$3, $4}' test.txt
17 this:is:AAAAAAA:a:test

地址:http://edu.51cto.com/lesson/id-17373.html

 

meetup
firebug

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值