Shell script-Three Musketeers (awk, egrep, sed) to extract strings

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
Insert picture description here
cat file name | awk -F "//"'{print $2}'
Insert picture description here
cat file name | grep -o "www. "
Insert picture description here
2. Extract 123.html
cat file name | awk -F'/''{ print $5}'
Insert picture description here
cat file name | grep -o "[0-9]
.html"
Insert picture description here
3. Extract http://www.51xit.top/root
cat file name | grep -o "http. root"
Insert picture description here
cat file name| sed's|(.
//. /. )(/. )|\1|'
Insert picture description here
4. Extract http:
cat file name | awk -F “//”'{print $1}'
Insert picture description here
cat file name | sed's ///www.
//'
Insert picture description here

5. Extract http://
cat file name | awk -F "w"'{print $1}'
Insert picture description here
cat file name | sed's/www.*//'
Insert picture description here
6. Extract root/123.html
cat file name | awk -F'www.51xit.top/''{print $2}'
Insert picture description here
cat file name | sed's/^.*top///'
Insert picture description here
7. Extract 123
cat file name | grep -o'[0-9]{ 3}'
Insert picture description here
cat file name | awk -F'/''{print $5}' | awk -F'.''{print $1}'
Insert picture description here

Guess you like

Origin blog.csdn.net/XCsuperman/article/details/108241959