cat a.txt
192.168.1.1 /hello1/b.do?bb=4
192.168.1.2 /hello2/a.do?ha=3
192.168.1.3 /hello3/r.do?ha=4
如何显示成以下效果?
192.168.1.1 b.do
192.168.1.2 a.do
192.168.1.3 r.do
解答:
方法一:
[ley@localhost script]$ awk ‘BEGIN{FIELDWIDTHS="11 9 4 5"}{print $1,$3}‘ a.txt
192.168.1.1 b.do
192.168.1.2 a.do
192.168.1.3 r.do
方法二:
[ley@localhost script]$ awk -F "/" ‘{print $1,$3}‘ a.txt |cut -c -17
192.168.1.1 b.do
192.168.1.2 a.do
192.168.1.3 r.do
方法三:
[ley@localhost script]$ awk -F " " ‘{print $1,$2}‘ a.txt|cut -d "/" -f1,3|sed ‘s#/##g‘|cut -d "?" -f1,3
原文地址:http://liangey.blog.51cto.com/9097868/1583222