xxx.xxxx.xxxx.tar.bz截取字符串的N种方法
时间:2009-08-21 来源:sss0213
xxx.xxxx.xxxx.tar.bz想要去掉后面两个域,输出结果为:xxx.xxxx.xxxx
- [root@zz common]# echo AIX.PI6002.090316.tar.Z | awk '{print substr($0,1,match($0,/\.[^\.]+\.[^\.]+$/)-1)}'
AIX.PI6002.090316
- [root@zz common]# echo AIX.PI6002.090316.tar.Z | awk -F "." '{for (i=1;i<NF-2;i++) printf $i".";print $(NF-2)}'
AIX.PI6002.090316 - [root@zz common]# echo AIX.PI6002.090316.tar.Z | awk -F "." '{$NF="";$(NF-1)=""}{print $0}'
AIX PI6002 090316 - [root@zz common]# echo AIX.PI6002.090316.tar.Z | awk -F . 'NF-=2'
AIX PI6002 090316 - [root@zz common]# echo "xxx.xxxx.xxxx.tar.bz" | awk '{print gensub(/(.*)\.[^\.]+\.[^\.]+/,"\\1",1)}'
xxx.xxxx.xxxx - [root@zz common]# echo AIX.PI6002.090316.tar.Z | awk -F"." '{print $1"."$2"."$3}'
AIX.PI6002.090316 - [root@zz common]# echo AIX.PI6002.090316.tar.Z | awk 'NF-=2' FS=. OFS=.
AIX.PI6002.090316 - [root@zz common]# echo "xxx.xxxx.xxxx.tar.bz" | awk -F . 'NF-=2' | sed 's/ /./g'
xxx.xxxx.xxxx - [root@zz common]# echo "xxx.xxxx.xxxx.tar.bz" | awk -F. 'NF-=2' OFS=.
xxx.xxxx.xxxx
相关阅读 更多 +