码迷,mamicode.com
首页 > 其他好文 > 详细

awk在正则表达式中的使用

时间:2017-08-09 23:40:04      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:awk在正则表达式中的使用

awk在正则表达式中的使用

1.1 ifconfig+sed定位+cut切割

1.1.1 取出网卡地址

定位

ifconfig eth0 |grep "inet addr"

方法五:

ifconfig eth0 |awk ‘NR==2‘|cut -d " "-f12|cut -d ":" -f2

10.0.0.200


1.2 tr命令

tr   精简版的,阉割版的sed命令

1对1的替换  通过输入重定向(<)读取文件

实例1-1 

echo abc |tr "abc" "123"

123

echo abcd |tr "abc" "123"

123d

echo abcba |tr "abc" "123"

12321

tr "a-z" "A-Z" <oldboy.txt

I AM HEYOG

cat oldboy.txt

i am heyog

 

实例1-2 

[root@oldboyedu-39-nb ~]# echo abc |tr"abc" "123"

123

[root@oldboyedu-39-nb ~]# echo abcba |tr"abc" "123"

12321


1.3 cut的使用

将linux权限解析出来

[root@oldboyedu-39-nb ~]# ls -l /etc/hosts

-rw-r--r--. 2 root root 216 May 20 22:57 /etc/hosts

[root@oldboyedu-39-nb ~]# ls -l /etc/hosts|cut -c2-10

rw-r--r--

[root@oldboyedu-39-nb ~]# ls -l /etc/hosts|cut -c2-10|tr "rwx-" "4210"

420400400


本文出自 “heyong” 博客,请务必保留此出处http://heyong.blog.51cto.com/13121269/1954913

awk在正则表达式中的使用

标签:awk在正则表达式中的使用

原文地址:http://heyong.blog.51cto.com/13121269/1954913

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!