linux shell script 求帮助

5毛 发布于 2013/04/19 09:46
阅读 237
收藏 1

用shell命令来做一个文本转换,或者帮忙讨论一下AWK 还是SED 的哪个语法可以实现....先谢谢了。


“AC_Owner_Portal_[Service_106300]”

To 

“AC Owner Portal (Service_106300)”

加载中
0
kid_d
kid_d
echo "\"AC_Owner_Portal_[Service_106300]\"" |\
sed 's/_/ /g;s/\[\([^ ]*\) \([^]]*\)\]/(\1_\2)/'
"AC Owner Portal (Service_106300)"

echo "\"AC_Owner_Portal_[Service_106300]\"" | \
awk -F'[][]' '{gsub("_"," ",$1);print $1"("$2")"$3}'
"AC Owner Portal (Service_106300)"

5毛
5毛
感谢您的解答
0
樊睿
樊睿
[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | sed 's/_\[\(Service_[0-9]\{6\}\)]/ (\1)/'
AC_Owner_Portal (Service_106300)
0
樊睿
樊睿
[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | perl -ne 's/_\[(Service_\d+)]/ ($1)/; print'
AC_Owner_Portal (Service_106300)
用perl处理貌似简单点
0
樊睿
樊睿
[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | perl -ne 's/_\[(Service_\d+)]/ ($1)/; print'
AC_Owner_Portal (Service_106300)  
5毛
5毛
AC Owner Portal (Service_106300) 要得到的前面部分是没有 _ 的哦
5毛
5毛
不懂perl好可耻。。。。
0
5毛
5毛
问你哦 这个 (\1) 是什么意思啊?在你这个sed里面 @樊睿  
樊睿
樊睿
回复 @totmann : QQ群,哈哈,你搜一下吧
totmann
totmann
第一个匹配的字符串,在这里就是Service_106300
0
樊睿
樊睿
[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | awk -F'[][]' '{gsub("_"," ",$1);print $1"("$2")"}' 
AC Owner Portal (Service_106300)
[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | sed -e 's/_/ /' -e 's/_/ /' -e 's/_\[\(Service_[0-9]\{6\}\)]/ (\1)/' 
AC Owner Portal (Service_106300)
[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | sed -e 's/_/ /g' -e 's/\(.*\)\[\([^]]*\)\]/\1(\2)/g' -e 's/Service /Service_/g'
AC Owner Portal (Service_106300)

[oracle@linux1 ~]$ echo "AC_Owner_Portal_[Service_106300]" | awk -F'[' -v OFS="" '{gsub(/_/," ",$1);sub(/]/,"",$2);$2="("$2")"}1'
AC Owner Portal (Service_106300)

From:Linux 犯罪团伙

樊睿
樊睿
回复 @5毛 : QQ群,哈哈,你搜一下吧
5毛
5毛
great! thanks a lot ! 这个linux犯罪团伙是什么组织啊?我可以加入你们去学习吗?
返回顶部
顶部