RedHat运维-Linux文本操作基础-牛客AWK

1. 查看static这个连接文件是否自动连接的命令是____________________________________;
2. 查看default这个连接文件是否自动连接的命令是_____________________________________;
3. 查看con0这个连接文件是否自动连接的命令是___________________________________;
4. 对于grep和sed来讲,在不开E的情况下就能生效的符号是. * ^ [ ] 以及__,而在开E的情况下才能生效的三个符号是 ( ) 以及____;
5. 对于grep和sed来讲,在不开E的情况下就能生效的符号是__ * ^ [ ] $,而在开E的情况下才能生效的三个符号是 ( __ |;
6. 对于grep和sed来讲,在不开E的情况下就能生效的符号是. * __ [ ] $,而在开E的情况下才能生效的三个符号是 __ ) |;
7. 将/etc/selinux/config文件中的"SELINUX=permissive"修改为"SELINUX=enforcing"的方法是__________________________________________;
8. 将/etc/selinux/config文件中的"SELINUX=enforcing"试探性地修改为"SELINUX=permissive"的方法是__________________________________________;
9. 对ps aux命令的结果(被保存到了文件nowcoder.txt当中)做统计,统计VSZ,RSS各自的总和(以M兆为单位统计),输出格式如下
MEM TOTAL
VSZ_SUM:3250.8M,RSS_SUM:179.777M
方法是_______________________________;
(ps aux命令的前10行结果为:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.1  0.4 107392 16268 ?        Ss   19:23   0:02 /usr/lib/systemd/systemd rhgb --switched-root --system --deserialize 31
root           2  0.0  0.0      0     0 ?        S    19:23   0:00 [kthreadd]
root           3  0.0  0.0      0     0 ?        I<   19:23   0:00 [rcu_gp]
root           4  0.0  0.0      0     0 ?        I<   19:23   0:00 [rcu_par_gp]
root           5  0.0  0.0      0     0 ?        I    19:23   0:01 [kworker/0:0-events]
root           6  0.0  0.0      0     0 ?        I<   19:23   0:00 [kworker/0:0H-events_highpri]
root           9  0.0  0.0      0     0 ?        I<   19:23   0:00 [mm_percpu_wq]
root          10  0.0  0.0      0     0 ?        S    19:23   0:00 [rcu_tasks_kthre]
root          11  0.0  0.0      0     0 ?        S    19:23   0:00 [rcu_tasks_rude_]
)
10. 从下列文本中,选出这样的值:
serverVersion:Apache Tomcat/8.5.15
serverName:8.5.15.0
osName:Windows
osVersion:10
文本为:
12-May-2017 10:02:22.789 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:Apache Tomcat/8.5.15
12-May-2017 10:02:22.813 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:May 5 2017 11:03:04 UTC
12-May-2017 10:02:22.813 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:8.5.15.0
12-May-2017 10:02:22.814 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:Windows, OS Version:10
12-May-2017 10:02:22.814 信息 [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:x86_64
其被保存在nowcoder.txt当中
11. nowcoder.txt的内容为:
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:6160            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 172.16.56.200:41856     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:49822     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:49674     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:42316     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:44076     172.16.240.74:6379      ESTABLISHED
tcp        0      0 172.16.56.200:49656     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:58248     100.100.142.4:80        TIME_WAIT
tcp        0      0 172.16.56.200:50108     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:41944     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:35548     100.100.32.118:80       TIME_WAIT
tcp        0      0 172.16.56.200:39024     100.100.45.106:443      TIME_WAIT
tcp        0      0 172.16.56.200:41788     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:58260     100.100.142.4:80        TIME_WAIT
tcp        0      0 172.16.56.200:41812     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:41854     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:58252     100.100.142.4:80        TIME_WAIT
tcp        0      0 172.16.56.200:49586     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:41754     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:50466     120.55.222.235:80       TIME_WAIT
tcp        0      0 172.16.56.200:38514     100.100.142.5:80        TIME_WAIT
tcp        0      0 172.16.56.200:49832     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:52162     100.100.30.25:80        ESTABLISHED
tcp        0      0 172.16.56.200:50372     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:50306     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:49600     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:41908     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:60292     100.100.142.1:80        TIME_WAIT
tcp        0      0 172.16.56.200:37650     100.100.54.133:80       TIME_WAIT
tcp        0      0 172.16.56.200:41938     172.16.34.144:3306      ESTABLISHED
tcp        0      0 172.16.56.200:49736     172.16.0.24:3306        ESTABLISHED
tcp        0      0 172.16.56.200:41890     172.16.34.144:3306      ESTABLISHED
udp        0      0 127.0.0.1:323           0.0.0.0:*
udp        0      0 0.0.0.0:45881           0.0.0.0:*
udp        0      0 127.0.0.53:53           0.0.0.0:*
udp        0      0 172.16.56.200:68        0.0.0.0:*
udp6       0      0 ::1:323                 :::*
raw6       0      0 :::58                   :::*                    7
编写shell脚本查看系统tcp连接中各个状态的连接数,并且按照连接数降序输出。你的脚本应该输出如下:
ESTABLISHED 22
TIME_WAIT 9
LISTEN 3
12. 接着第11题,查看和本机3306端口建立连接并且状态是established的所有IP,按照连接数降序排序。你的脚本应该输出
10 172.16.0.24
9 172.16.34.144
1 172.16.34.143
13. 接着第11题,输出每个IP的连接数,按照连接数降序排序。你的脚本应该输出
172.16.0.24 10
172.16.34.144 9
100.100.142.4 3
0.0.0.0 3
172.16.34.143 1
172.16.240.74 1
120.55.222.235 1
100.100.54.133 1
100.100.45.106 1
100.100.32.118 1
100.100.30.25 1
100.100.142.5 1
100.100.142.1 1
14. 接着第11题,输出和本机3306端口建立连接的各个状态的数目,按照以下格式输出
TOTAL_IP表示建立连接的ip数目
TOTAL_LINK表示建立连接的总数目
TOTAL_IP 3
ESTABLISHED 20
TOTAL_LINK 20
15. 假设 Nginx 的日志存储在 nowcoder.txt 里,内容如下:
192.168.1.20 - - [21/Apr/2020:14:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [21/Apr/2020:15:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [21/Apr/2020:21:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.23 - - [21/Apr/2020:22:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.24 - - [22/Apr/2020:15:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [22/Apr/2020:15:26:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:08:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:09:20:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:10:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:10:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:14:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:15:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:15:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [23/Apr/2020:16:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.24 - - [23/Apr/2020:20:27:49 +0800] "GET /2/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.25 - - [23/Apr/2020:20:27:49 +0800] "GET /3/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.20 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.22 - - [23/Apr/2020:15:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
192.168.1.21 - - [23/Apr/2020:20:27:49 +0800] "GET /1/index.php HTTP/1.1" 404 490 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0"
现在需要编写 Shell 脚本统计出 2020 年 4 月 23 号访问 IP 的对应次数,并且按照次数降序排序。你的脚本应该输出:
5 192.168.1.22
4 192.168.1.21
3 192.168.1.20
2 192.168.1.25
1 192.168.1.24
16. 接15题,
现在需要编写 Shell 脚本统计 2020年04月23日20点至23点去重后的 IP 访问量,你的脚本应该输出:
5
输出说明:2020年04月23日20点至23点,共有 192.168.1.24、192.168.1.25、192.168.1.20、192.168.1.21、192.168.1.22 共 5 个 IP 访问了。
17. 接15题,
现在需要编写shell脚本统计访问3次以上的IP,你的脚本应该输出:
6 192.168.1.22
5 192.168.1.21
4 192.168.1.20
18. 接15题,
假设Nginx的日志存储在nowcoder.txt里,内容如下:
现在需要编写shell脚本查询192.168.1.22的详细访问次数情况,按访问频率降序排序。你的脚本应该输出:
4 /1/index.php
2 /3/index.php
19. 接15题,
假设nginx的日志存储在nowcoder.txt里,内容如下:
现在需要编写shell脚本统计百度爬虫抓取404的次数,你的脚本应该输出
2
20. 接15题,
假设Nginx的日志存储在nowcoder.txt里,内容如下:
现在需要编写Shell脚本统计每分钟的请求数,并且按照请求数降序排序。你的脚本应该输出:
5 20:27
4 15:00
2 22:10
2 14:12
2 10:27
1 23:59
1 21:21
1 16:15
1 15:26
1 09:20
1 08:05
21. 
有一个文本文件nowcoder.txt,假设内容格式如下:
111:13443
222:13211
111:13643
333:12341
222:12123
现在需要编写一个shell脚本,按照以下的格式输出:
[111]
13443
13643
[222]
13211
12123
[333]
12341
22. 
有一个文件nowcoder.txt,里面的每一行都是一个数字串,编写一个shell脚本对文件中每一行的数字串进行格式化:每3个数字加入一个逗号(,)。
例如:数字串为“123456789”,那么需要格式化为123,456,789。
假设nowcoder.txt内容如下:
1
12
123
1234
123456
那么你的脚本输出如下:
1
12
123
1,234
123,456
23. 
假设有一个nowcoder.txt,编写脚本,打印只有一个数字的行。
假设nowcoder.txt内容如下:
haha
1
2ab
cd
77
那么你的脚本应该输出
1
2ab
24. 
假设有一些域名,存储在nowcoder.txt里,现在需要写一个shell脚本,将域名取出并根据域名进行计数排序处理(降序)。
假设nowcoder.txt内容如下:
http://www.nowcoder.com/index.html
http://www.nowcoder.com/1.html
http://m.nowcoder.com/index.html
你的脚本应该输出:
2 www.nowcoder.com
1 m.nowcoder.com
25. 
编写一个shell脚本,将文件nowcoder.txt中每一行的字段逆序输出,其中字段之间使用英文冒号:相分隔。
假设nowcoder.txt内容如下:
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
你的脚本应当输出
/usr/bin/false:/var/empty:Unprivileged User:-2:-2:*:nobody
/bin/sh:/var/root:System Administrator:0:0:*:root
26. 
写一个脚本统计文件nowcoder.txt中的每一行是否是正确的IP地址。
如果是正确的IP地址输出:yes
如果是错误的IP地址,且是四段号码的话输出:no,否则的话输出:error
假设nowcoder.txt内容如下:
192.168.1.1
192.168.1.0
300.0.0.0
123
你的脚本应该输出:
yes
yes
no
error
27. 
写一个bash脚本以实现一个需求,去掉输入中含有B和b的单词
示例:
假设输入如下:
big
nowcoder
Betty
basic
test
你的脚本获取以上输入应当输出:
nowcoder test
说明:
你可以不用在意输出的格式,空格和换行都行
28. 
写一个bash脚本以实现一个需求,求输入的一个数组的平均值
第1行为输入的数组长度N
第2~N行为数组的元素,如以下为:
数组长度为4,数组元素为1 2 9 8
示例:
4
1
2
9
8
那么平均值为:5.000(保留小数点后面3位)
你的脚本获取以上输入应当输出:
5.000
29. 
编写一个shell脚本以实现如下功能:去掉输入中含有this的语句,把不含this的语句输出
示例:
假设输入如下:
that is your bag
is this your bag?
to the degree or extent indicated.
there was a court case resulting from this incident
welcome to nowcoder
你的脚本获取以上输入应当输出:
that is your bag
to the degree or extent indicated.
welcome to nowcoder
说明:
你可以不用在意输出的格式,包括空格和换行
30. 
写一个bash脚本,统计一个文本文件nowcoder.txt中每一行出现的1~5数字的个数,并且计算一下整个文档中一共出现了几个1~5数字的总数。
示例:
假设 nowcoder.txt 内容如下:
a12b8
10ccc
2521abc
9asf
你的脚本应当输出:
line1 number: 2
line2 number: 1
line3 number: 4
line4 number: 0
sum is 7
说明:
不要担心你输出的空格以及换行的问题
31. 
写一个bash脚本来转置文本文件nowcoder.txt中的文件内容。
文件中每行列数相同,并且每个字段由空格分隔
示例:
假设 nowcoder.txt 内容如下:
job salary
c++ 13
java 14
php 12
你的脚本应当输出(以词频升序排列):
job c++ java php
salary 13 14 12
32. 
给定一个nowcoder.txt文件,其中有3列信息,如下:
20201001 python 99
20201002 go 80
20201002 c++ 88
20201003 php 77
20201001 go 88
20201005 shell 89
20201006 java 70
20201008 c 100
20201007 java 88
20201006 go 97
编写一个shell脚本来检查文件第二列是否有重复,且有几个重复,并提取出重复的行的第二列信息(先按次数排序,如果次数相同,按照单词字母顺序排序),输入如下:
2 java
3 go
33. 
写一个bash脚本以统计一个文本文件nowcoder.txt 中每个单词出现的个数。

为了简单起见,你可以假设:
nowcoder.txt只包括小写字母和空格,每个单词只由小写字母组成,单词间由一个或多个空格字符分隔。

示例:
假设 nowcoder.txt 内容如下:
welcome nowcoder
welcome to nowcoder
nowcoder
你的脚本应当输出(以词频升序排列):
to 1 
welcome 2 
nowcoder 3 

说明:
不要担心个数相同的单词的排序问题,每个单词出现的个数都是唯一的。
34. 
假设 nowcoder.txt 内容如下:
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.4  77744  8332 ?        Ss    2021   1:15 /sbin/init noibrs splash
root         2  0.0  0.0      0     0 ?        S     2021   0:00 [kthreadd]
root         4  0.0  0.0      0     0 ?        I<    2021   0:00 [kworker/0:0H]
daemon     486  0.0  0.1  28340  2372 ?        Ss    2021   0:00 /usr/sbin/atd -f
root       586  0.0  0.3  72308  6244 ?        Ss    2021   0:01 /usr/sbin/sshd -D
root     12847  0.0  0.0   4528    68 ?        S<   Jan03   0:13 /usr/sbin/atopacctd
root     16306  1.7  1.2 151964 26132 ?        S<sl Apr15 512:03 /usr/local/aegis/aegis_client/aegis_11_25/AliYunDun
root     24143  0.0  0.4  25608  8652 ?        S<Ls 00:00   0:03 /usr/bin/atop -R -w /var/log/atop/atop_20220505 600
root     24901  0.0  0.3 107792  7008 ?        Ss   15:37   0:00 sshd: root@pts/0
root     24903  0.0  0.3  76532  7580 ?        Ss   15:37   0:00 /lib/systemd/systemd --user
root     24904  0.0  0.1 111520  2392 ?        S    15:37   0:00 (sd-pam)
以上内容是通过ps aux命令输出到nowcoder.txt文件中的,请你写一个脚本计算一下所有进程占用内存大小的和。
35. 
写一个bash脚本以统计一个文本文件nowcoder.txt中字母数小于8的单词。
示例:
假设 nowcoder.txt 内容如下:
how they are implemented and applied in computer

你的脚本应当输出:
how
they
are
and
applied
in

说明:
不用担心你输出的空格以及换行的问题
36. 
编写一个shell脚本以输出一个文本文件nowcoder.txt中空行的行号(空行可能连续,从1开始输出)

示例:
假设 nowcoder.txt 内容如下:
a
b

c

d

e


f
你的脚本应当输出:
3
5
7
9
10
37. 
编写一个bash脚本以输出一个文本文件nowcoder.txt中第5行的内容。

示例:
假设 nowcoder.txt 内容如下:
welcome
to
nowcoder
this
is
shell
code
你的脚本应当输出:
is
38. 
写一个 bash脚本以输出数字 0 到 500 中 7 的倍数(0 7 14 21...)的命令


1. nmcli con show static | grep 'connection\.autoconnect'
2. nmcli con show default | grep 'connection\.autoconnect'
3. nmcli con show con0 | grep 'connection\.autoconnect'
4. $    |
5. .    )
6. ^    (
7. sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
8. sed -n 's/^SELINUX=.*/SELINUX=permissive/p' /etc/selinux/config
9. 
echo MEM TOTAL
vsz_sum=`awk 'NR>1{sum+=$5} END{print sum/1024}' nowcoder.txt`
rss_sum=`awk 'NR>1{sum+=$6} END{print sum/1024}' nowcoder.txt`
echo VSZ_SUM:"$vsz_sum"M,RSS_SUM:"$rss_sum"M
10. 
serverVersion=`grep 'Server version' nowcoder.txt | awk -F 'Server version:' '{print $2}'`
serverName=`grep 'Server number' nowcoder.txt | awk -F 'Server number:' '{print $2}'`
osName=`grep 'OS Name' nowcoder.txt | awk -F 'OS Name:' '{print $2}' | awk -F ', OS Version:' '{print $1}'`
osVersion=`grep 'OS Name' nowcoder.txt | awk -F 'OS Name:' '{print $2}' | awk -F ', OS Version:' '{print $2}'`
echo serverVersion:"$serverVersion"
echo serverName:"$serverName"
echo osName:"$osName"
echo osVersion:"$osVersion"
11. 
ESTABLISHED=`awk '$1=="tcp" && $6=="ESTABLISHED"{count++} END{print count}' nowcoder.txt`
TIME_WAIT=`awk '$1=="tcp" && $6=="TIME_WAIT"{count++} END{print count}' nowcoder.txt`
LISTEN=`awk '$1=="tcp" && $6=="LISTEN"{count++} END{print count}' nowcoder.txt`
echo -e ESTABLISHED "$ESTABLISHED""\n"TIME_WAIT "$TIME_WAIT""\n"LISTEN "$LISTEN""\n" | sort -k2 -nr
12. 
awk '{print $5}' nowcoder.txt | awk -F':' '{if($2=="3306"){array[$1]+=1}} END{for(item in array){print array[item], item}}' | sort -k1 -nr
13. 
awk '$1=="tcp"{print $5}' nowcoder.txt | awk -F':' '{array[$1]+=1} END{for(item in array) {print item, array[item]}}' | sort -k2 -nr
14. 
awk '{print $5}' nowcoder.txt | awk -F':' '{if($2=="3306"){array[$1]+=1}} END{for(item in array){count++} print "TOTAL_IP", count}'
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "ESTABLISHED", count}' nowcoder.txt
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "TOTAL_LINK", count}' nowcoder.txt
或者
echo TOTAL_IP `awk '{print $5}' nowcoder.txt | awk -F':' '$2=="3306"{print $1}' | sort | uniq | wc -l`
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "ESTABLISHED", count}' nowcoder.txt
awk '$6=="ESTABLISHED"&&$5~/3306/{count++} END{print "TOTAL_LINK", count}' nowcoder.txt
15. 
grep '23/Apr/2020' nowcoder.txt | awk '{array[$1]+=1} END{for(item in array) {print array[item], item}}' | sort -k1 -rn
16. 
grep '23/Apr/2020' nowcoder.txt | awk -F':' '$2>=20&&$2<=23{print $1}' | awk '{print $1}' | sort | uniq | wc -l
17. 
awk '{array[$1]+=1} END{for(item in array) {if(array[item]>3) {print array[item], item}}}' | sort -k1 -rn
18. 
grep '192\.168\.1\.22' nowcoder.txt | awk -F'GET ' '{print $2}' | awk '{array[$1]+=1} END{for(item in array) {print array[item], item}}' | sort -k1 -rn
19. 
grep 'Baiduspider' nowcoder.txt | awk -F'"' '{print $2}' | sort | uniq | wc -l
20. 
awk -F':' '{array[$2":"$3]+=1} END{for(item in array) {print array[item], item}}' nowcoder.txt | sort -k1 -rn
21. 
awk -F':' '{array[$1]=array[$1]"\n"$2} END{for(item in array) {print "["item"]"array[item]}}'
22. 
awk 'BEGIN{FS=""}{
    for(i=1;i<=NF;i++){
        if((NF-i)%3==0 && NF-i!=0){
            printf("%s,", i);
        }
        else{
            printf("%s", i);
        }
    }
    printf("\n")
}' nowcoder.txt
23. 
awk -F'[[:digit:]]' '{if(NF==2) print $0}' nowcoder.txt
24. 
awk -F'/' '{array[$3]+=1} END{for(item in array) {print array[item], item}}' nowcoder.txt | sort -rn -k1
25. 
awk -F':' '{for(i=NF; i>1; i--) {printf("%s:", $i)} printf("%s\n", $1)}' nowcoder.txt
或者
awk -F':' '{str=$NF; for(i=NF-1;i>=1;i--) {str=str":"$i} print str}' nowcoder.txt
26. 
awk -F'.' '{
    if(NF!=4) print "error"
    else{
        for(i=1; i<=4;i++){
            if($i>255 || $i<0){
                print "no"
                break
            }
        }
        if(i==5) print "yes"
    }
}' nowcoder.txt
27. 
grep -v 'B\|b' nowcoder.txt
28. 
read N
for i in `seq $((N))`
do
    read temp
    sum=$((sum+temp))
done
echo "scale=3; $sum/$N" | bc
29. 
grep -v 'this' nowcoder.txt
30. 
awk 'BEGIN{FS=""} {
    array[NR]=0
    for(i=1;i<=NF;i++){
        if($i>=1 && $i<=5){
            array[NR]+=1
        }
    }
}
END{
    for(item in array) {print "line"item" number: "array[item]}
    for(item in array) {sum+=array[item]}
    print "sum is "sum
}' nowcoder.txt
31. 
awk '{
    for(i=1;i<=NF;i++) {
        array[i]=array[i]" "$i
    }
}
END{
    for(i=1;i<=NF;i++) print array[i]
}' nowcoder.txt | sort
32. 
awk '{array[$2]+=1} END{
    for(item in array){
        if(array[item]!=1) print array[item], item
    }
}' nowcoder.txt | sort -k1 -n
33. 
awk '{for(i=1;i<=NF;i++) array[$i]+=1} END{
    for(item in array) {
        print item, array[item]
    }
}' nowcoder.txt | sort -k2 -n
34. 
awk '{sum+=$4} END{print sum}' nowcoder.txt
35. 
awk '{for(i=1;i<=NF;i++){
    if(length($i)<8) print $i
}}' nowcoder.txt
36. 
awk '/^$/{print NR}' nowcoder.txt
37. 
awk '{if(NR==5)print $0}' nowcoder.txt
38. 
for i in `seq 0 500`
do
    [ $((i%7)) -eq 0 ] && echo $i
done
exit 0

  • 36
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值