1. 例子
http://www.test.com/atk/pki/test-1.1.tar.gz
过滤出test-1.1.tar.gz
t = http://www.test.com/atk/pki/test-1.1.tar.gz
(1) egrep -o "[^/]+$"
(2) echo ${line##*/}
(3) awk -F/ '{print $NF}' t
2. 取IP
ifconfig eth0 | grep "inet addr" | awk '{print $2}' | cut -d: -f2
ifconfig eth0 | egrep -o 'addr:[0-9\.]+' |cut -d: -f2
ifconfig eth0 | egrep -o 'addr:[0-9\.]{7,}' | head -n1
ifconfig eth0 | awk -F'[: ]+' 'inet addr/{print $4}'
ifconfig eth0 | awk -F'[[:space:]:]+' '/inet addr/{print $4}'
3. 提取网页中htmlMP4文件
egrep -o '[^><]+mp4<' *.html
egrep -o '[^*><]+mp4' *.html
awk -F '<a[^>]+>|</a>' '{for(i=1;i<=NF;i++){if(match($i,"mp4"))print $i}}'
awk 'BEGIN(RS=">|<") /mp4$/{print($0)}'