awk and sed command finishing face questions

1, sed command
123abc456
456def123
567abc789
789def567
required output:
456ABC123
123DEF456
789ABC567
567DEF789
Answer:
Sed -R & lt -i 'S # (...) (...) # \. 5 \ U \ (.) (.) (.) 2 \ u \ 3 \ u \ 4 \ 1 # g '22.txt
return
sed -r -i' s # (... ) (.) (.) (.) (...) # \ 5 \ l \ 2 \ l \ 3 \ l \ 4 \ 1 # g '22.txt

2, awk command
100
A 100
B -50
C -20
D -30
required output results:
100
A 100
200 is
B -50
150
C -20
130.
D -30
Answer:
awk 'SUM = $ + $ +. 1 2 {IF (= NR = 1) print $ 1; else if (NR == 5) print $ 0; else print $ 1 "\ t" $ 2 "\ n" sum} '11.txt

3, a shell Tencent questions
assume file contents qq tel:
12334: 13510014336
12345: 12,334,555,666
12334: 12343453453
12099: 13,598,989,899
12334: 12,345,454,545
12099: 12343454544
classified as follows:
[12334]
13510014336
12343453453
.......... .
[12099]
13,598,989,899
12,343,454,544

答案:
[root@localhost ~]# cat qq.tel | sort -r | awk -F: '{if (tmp!=$1) {tmp=$1;print "["tmp"]"} print $2}'
[12345]
12334555666
[12334]
13510014336
12345454545
12343453453
[12099]
13598989899
12343454544

4, [Tencent face questions]: a type of text file, which is stored in each row
Lander's IP (some lines are duplicated), write a shell script output
up to landing the number of users.
IP as follows:
. 219.217.49 14
175.43.4.87
87.48.98.1
59.73.38.25
219.217.50.14
59.92.48.32
219.217.49.14
59.72.38.142
59.73.38.25
219.217.49.14


5, the processing at the file contents, and the domain name taken counting the number of rows, such as processing:;
HTTP:... COM baidu WWW // / HTML index
. HTTP: / / WW .baidu COM / 1.html
HTTP: / / the WWW baidu COM / 2 HTML...
HTTP: / / POST baidu COM / index HTML...
HTTP: / / MP3 baidu COM / index HTML...
HTTP:... / / the WWW baidu COM / 3 HTML
HTTP: / /post.baidu com / 2 html..
to give F as a result: the number of occurrences of the domain name, the domain name
. 4 WWW baidu COM..
2 POST .baidu COM.
. 1 baidu MP3 COM..

答案:
[root@localhost ~]# awk -F/ '{print $3}' yuming.txt | sort -r | uniq -c
4 www.baidu.com
2 post.baidu.com
1 mp3.baidu.com

 

Guess you like

Origin www.cnblogs.com/lyqlyqlyq/p/11489904.html