标签:
tr,awk,sed
1.大小写转换
[zhangping10@yf-nsop-dev01.yf01.baidu.com ~]$ echo "a b c 2011-11-22 a:d" | awk ‘{$2=gsub(/-/,"",$4);print $0}‘ a 2 c 20111122 a:d
[zhangping10@yf-nsop-dev01.yf01.baidu.com ~]$ echo "a b c 2011-11-22 a-d" | awk ‘{$6=gensub(/-/,"",1,$4);print $0}‘ a b c 2011-11-22 a-d 201111-22
gensub(/-/,"",1,$4)
/-/:替换源
"":替换目标
1:替换第几次,"g","G"表示全局替换
$4:替换第几个字段
替换目标还可以使用分组
[zhangping10@yf-nsop-dev01.yf01.baidu.com ~]$ echo "duowan duowan-0002-gs2 a" | awk ‘{$0=gensub(/^.*-([0-9]+)(-.*)$/,"\\2","g",$2);print $0}‘ -gs2
标签:
原文地址:http://www.cnblogs.com/zlingh/p/4676744.html