依然饭跑跑 发表于 2015-9-10 08:07:59

awk用法

  grep:文本过滤器,
grep "pattern"input_file ....
  sed: 流编辑器;
sed "command/PATTERD/"
  awk:报告生成器。能够将输入的信息格式化之后显示;包括nawk版本,gawk版本
  用法:
  awk 'script' file1 file2, ...
  awk '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.iyunv.com/lesson/id-17373.html
  
  meetup
firebug
页: [1]
查看完整版本: awk用法