日期:2014-05-16  浏览次数:20572 次

还是字段截取问题啊!---sed / awk
有如下字段:SCRIPTNAME "/export/opt/bank_scripts/ALSBSCORE.sh" 
怎么才能把后面的SH 名字取出来啊? 
得到:ALSBSCORE.sh 
各位大哥,帮帮忙啊!

------解决方案--------------------
[u@H /billing/user/test]$basename /export/opt/bank_scripts/ALSBSCORE.sh
ALSBSCORE.sh

[u@H /billing/user/test]$echo "/export/opt/bank_scripts/ALSBSCORE.sh"|awk -F'/' '{print $5}'
ALSBSCORE.sh
------解决方案--------------------
Perl code

#cat testtext 
SCRIPTNAME "/export/opt/bank_scripts/ALSBSCORE.sh"


#cat sub.sed 
s/"//g
s/\/[^\/]\+\//\//g
s/\/[^\/]\+\///


#sed -f sub.sed testtext | awk '{print $2}'
ALSBSCORE.sh

------解决方案--------------------
awk -F'[/"]' '{print $(NF-1)}'
------解决方案--------------------
果然是UNIX问题,这个问题好像问过了以前

cat 1 | awk -F/ '{print $NF}' | tr -d '"'