-
取本機ip地址
利用head命令取行首兩行,tail命令取行尾一行,
ifconfig |head -2 |tail -1
利用tr -s命令替換空格為“:”,并合并重復的“:”。利用cut -d:-f3命令,保留以“:”為分割符的第三部分
ifconfig |head -2 |tail -1 |tr -s " " ":" |cut -d: -f3
2. 取各分區利用率的數值
利用tr -s命令將df文件的分隔符空格替換并合并重復
[root@localhost ~]# df |tr -s " " ":"
利用cut -d命令選擇以“:”為分隔符的第5列,利用tr-d命令刪除文件中的“%”
[root@localhost ~]# df |tr -s " " ":" |cut -d: -f5 |tr -d %
3. 統計/etc/init.d/functions 文件中每個單詞出現的次數,并按頻率從高到低顯示
用tr -cs命令顯示文件中全部以字母組成的字符串,并換行
~]# cat /etc/init.d/functions | tr -cs "[:alpha:]" "\n"
用“sort”命令對文件進行排序,“unip -c”顯示每行重復數 “sort -nr”進行逆排序
~]# cat /etc/init.d/functions |sort |unip -c |sort -nr
4. /etc/rc.d/init.d/functions或/etc/rc.d/init.d/functions/" 取目錄名
用正則表達式“egrep -o”命令,僅顯示匹配到的自負串
~]# echo /etc/rc.d/init.d/functions |egrep -o "/.*/"
5. 正則表達式表示身份證號 .
新建一文件zhou 用"egrep"命令0-9開頭,17位數字字符,1位數字或字母任意字符結尾的字符串
[root@localhost ~]# cat /testdir/zhou |egrep "\<[0-9]{17}[[:alnum:]]\>"
6. 正則表達式表示手機號
[root@localhost ~]# cat /testdir/zhou |egrep "\<1[0-9]{9}[[:digit:]]\>"
7. 正則表達式表示郵箱
[root@localhost ~]# egrep "^([a-zA-Z0-9_\-\.\+]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"
8. 正則表達式表示QQ號
[root@localhost ~]# egrep "\<[1-9][0-9]{4,11}\>"
這個題qq號和手機號分不開,待解決,有11位的QQ號和手機號是一樣的
原創文章,作者:191095336,如若轉載,請注明出處:http://www.www58058.com/30951