好吧,趁着鸡血效果还在,抓紧学习
vi text.txt
1 2 3 4 5 |
F115!16201!1174113017250745 10.86.96.41 211.140.16.1 200703180718 F125!16202!1174113327151715 10.86.96.42 211.140.16.2 200703180728 F235!16203!1174113737250745 10.86.96.43 211.140.16.3 200703180738 F245!16204!1174113847250745 10.86.96.44 211.140.16.4 200703180748 F355!16205!1174115827252725 10.86.96.45 211.140.16.5 200703180758 |
然后第一个命令:
awk {print} text.txt
这个就是全部打印了….
第二个命令:
awk ‘/F[12].*/’ {print}
等价于:awk ‘/F[12].*/’ test.txt
第三个命令:
awk ‘/F[12].*/{print $1,$3}’ test.txt
输出第1,3列,此处注意,两个’的位置 ,$1,$3中间的,号
结果如下:
1 2 3 4 5 |
[root@jmx shell]# awk '/F[12].*/{print $1,$3}' test.txt F115!16201!1174113017250745 211.140.16.1 F125!16202!1174113327151715 211.140.16.2 F235!16203!1174113737250745 211.140.16.3 F245!16204!1174113847250745 211.140.16.4 |
第四个命令:
awk -F'[ !]’ ‘/F[12].*/ {print substr($3,6)}’ test.txt
1 2 3 4 5 6 |
[root@jmx shell]# awk -F'[ !]' '/F[12].*/ {print substr($3,6)}' test.txt 13017250745 13327151715 13737250745 13847250745 [root@jmx shell]# |
第五个命令:
awk ‘NR % 2 == 1′ test.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@jmx shell]# awk 'NR % 2 == 1' test.txt F115!16201!1174113017250745 10.86.96.41 211.140.16.1 200703180718 F235!16203!1174113737250745 10.86.96.43 211.140.16.3 200703180738 F355!16205!1174115827252725 10.86.96.45 211.140.16.5 200703180758 [root@jmx shell]# awk 'NR%2 == 1' test.txt F115!16201!1174113017250745 10.86.96.41 211.140.16.1 200703180718 F235!16203!1174113737250745 10.86.96.43 211.140.16.3 200703180738 F355!16205!1174115827252725 10.86.96.45 211.140.16.5 200703180758 [root@jmx shell]# awk 'NR%2==1' test.txt F115!16201!1174113017250745 10.86.96.41 211.140.16.1 200703180718 F235!16203!1174113737250745 10.86.96.43 211.140.16.3 200703180738 F355!16205!1174115827252725 10.86.96.45 211.140.16.5 200703180758 [root@jmx shell]# |
运行结果做了空格的测试,貌似不印象结果….
时间:2012-11-12 23:18:53
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021