正则表达案例【一】

来源:互联网 发布:怎样设置网站主域名 编辑:程序博客网 时间:2024/05/18 03:44

【1】ifconfig ens33 | awk -F" "  'NR==2 { print $4 }'

         ifconfig ens33 | grep -n inet | sed  -n 1p | awk '{print $3}'

          ifconfig ens33 | awk -F '[ :]+' 'NR==2 { print $3 }'   #多分隔符 匹配

 【2】转化文件wxr  

          ll txt.txt |cut -c 2-10 | tr rwx- 4210 |awk '{for (i=1;i<=length($1);i++) {s=substr($1,i,1);printf s""} }'|awk '{print (($1+$2+$3)) $4+$5+$6 $7+$8+$9 }'

        stat txt.txt  |sed -n 4p | cut -d "(" -f2 |cut -c 1-4

【3】find . -type f -name "*.sh" |xargs -i  cp {}  test/  

        xargs的一个选项-I,使用-I指定一个替换字符串{},这个字符串在xargs扩展时会被替换掉,当-I与xargs结合使用,每一个参数命令都会被执行一次

 【4】grep -v grep 代表在查询的最终结果中去掉grep命令本身

     示例如下:

     [root@huawei shell]# ps -ef | grep pid.sh|grep -v grep
     [root@huawei shell]# sh pid.sh&
     [1] 10867
     [root@huawei shell]# ps -ef | grep pid.sh | grep -v grep
     root     10867 19137  0 16:58 pts/0    00:00:00 sh pid.sh
     [root@huawei shell]# ps -ef | grep pid.sh
     root     10867 19137  0 16:58 pts/0    00:00:00 sh pid.sh
     root     10875 19137  0 16:58 pts/0    00:00:00 grep --color=auto pid.sh

 【4】每1秒刷新CPU的使用率排序

      watch -n 1 'ps -aux --sort -pcpu' 


xargs的一个选项-I,使用-I指定一个替换字符串{},这个字符串在xargs扩展时会被替换掉,当-I与xargs结合使用,每一个参数命令都会被执行一次:

来自: http://man.linuxde.net/xargs
xargs的一个选项-I,使用-I指定一个替换字符串{},这个字符串在xargs扩展时会被替换掉,当-I与xargs结合使用,每一个参数命令都会被执行一次:

来自: http://man.linuxde.net/xargs