Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 938 Bytes

98.md

File metadata and controls

49 lines (33 loc) · 938 Bytes

题目要求

利用你学过的知识点,想办法根据要求截取出字符。

字符串var=http://www.aaa.com/root/123.htm

1.取出www.aaa.com/root/123.htm

2.取出123.htm

3.取出http://www.aaa.com/root

4.取出http:

5.取出http://

6.取出root/123.htm

7.取出123

参考答案

#!/bin/bash
#这个脚本用来截取字符串
#作者:猿课-阿铭 www.apelearn.com
#日期:2018-12-19
var=http://www.aaa.com/root/123.htm
echo "1.取出www.aaa.com/root/123.htm"
echo $var |awk -F '//' '{print $2}'

echo "2.取出123.htm"
echo $var |awk -F '/' '{print $5}'

echo "3.取出http://www.aaa.com/root"
echo $var |sed 's#/123.htm##'

echo "4.取出http:"
echo $var |awk -F '//' '{print $1}'

echo "5.取出http://"
echo $var |awk -F 'www' '{print $1}'

echo "6.取出root/123.htm"
echo $var |awk -F 'com/' '{print $2}'
echo $var |awk -F '/' '{print $4"/"$5}'

echo "7.取出123"
echo $var |sed 's/[^0-9]//g'