Use shell Three Musketeers to extract strings
String: http://www.51xit.top/root/123.html
First edit the file vi 123.txt
http://www.51xit.top/root/123.html
Requirements:
1. Extract www.51xit.top/root/123.html
2. Extract 123.html
3. Extract http://www.51xit.top/root
4. Extract http:
5. Extract http://
6. Extract root/123.html
7, extract 123
Steps: (Note: The following is the file I created in Chinese is easy to remember, please create in English)
1. Extract www.51xit.top/root/123.html
awk -F “//”'{print $2 }'file name
cat file name | awk -F "//"'{print $2}'
cat file name | grep -o "www. "
2. Extract 123.html
cat file name | awk -F'/''{ print $5}'
cat file name | grep -o "[0-9] .html"
3. Extract http://www.51xit.top/root
cat file name | grep -o "http. root"
cat file name| sed's|(. //. /. )(/. )|\1|'
4. Extract http:
cat file name | awk -F “//”'{print $1}'
cat file name | sed's ///www. //'
5. Extract http://
cat file name | awk -F "w"'{print $1}'
cat file name | sed's/www.*//'
6. Extract root/123.html
cat file name | awk -F'www.51xit.top/''{print $2}'
cat file name | sed's/^.*top///'
7. Extract 123
cat file name | grep -o'[0-9]{ 3}'
cat file name | awk -F'/''{print $5}' | awk -F'.''{print $1}'