0
点赞
收藏
分享

微信扫一扫

awk第一天

修炼之士 03-19 21:45 阅读 2

awk第一天

1.用awk 打印整个test.txt (以下操作都是用awk工具实现,针对test.txt)

awk '{print}' test.txt






[root@master ~]# awk '{print}' test.txt
hello world\!
usr/root
usr/root
usr/root
usr/root
usr/root
usr/root

ceshi2023
kaifa
sheji
xiaoshou
dsfhjas
sdhfash
fkshfsegh
fjksfhs


ejifhes

ejkfhesghfe
ekfesg
ejkfehfitye
ejnsfhweguf
ekfjheigie


ejrgisegfe

jegifgeuig
ekfhegu

ejieuigf
ekfieif

2.查找所有包含 ‘bash’ 的行

awk '/bash/' test.txt

3 .用 ‘:’ 作为分隔符,查找第三段等于0的行

awk -F ":" '$3==0' test.txt
或者
awk -F : '{print $3}' test.txt




[root@master ~]# awk -F : '{print $3}' test.txt
100
90
60
80
100
95
168
75
100

4.用 ‘:’ 作为分隔符,查找第一段为 ‘root’ 的行,并把该段的 ‘root’ 换成 ‘toor’ (可以连同sed一起使用)

awk -F: '$1=="root"' awk | sed s/root/toor/g

5.用 ‘:’ 作为分隔符,打印最后一段

redis 文本
work 16067 /data/svr/redis/bin/redis-server:6403
work 16067 /data/svr/redis/bin/redis-server
:6403
work 16067 /data/svr/redis/bin/redis-server:6403
work 16067 /data/svr/redis/bin/redis-server
:6403

awk -F ":" '{print $NF}' awk

6
如何打印第二列pid 和最后一列端口打印出来 ,请给出命令

输出结果如下:
16067 6403
16067 6403
16067 6403
16067 6403

awk -F "[ :]+" '{print $2,$4}'



[root@master ~]# cat redis |awk -F "[ :]+" '{print $2,$4}'
16067 6403
16067 6403
16067 6403
16067 6403

7 linux系统中如何获取 pid 9257的进程号监听的端口是什么 给出命令

lsof -p 9527 -iTCP | grep LISTEN

netstat -tulpn | grep '9257'

ss -tulpn | grep '9257'





[root@master ~]# lsof -p 9257 -iTCP |grep LISTEN
sshd     976 root    3u  IPv4  16558      0t0  TCP *:ssh (LISTEN)
sshd     976 root    4u  IPv6  16560      0t0  TCP *:ssh (LISTEN)
master  1203 root   13u  IPv4  17191      0t0  TCP localhost:smtp (LISTEN)
master  1203 root   14u  IPv6  17192      0t0  TCP localhost:smtp (LISTEN)

8 .查出实时 哪个IP地址连接最多 哪个ip 访问大于 1000次 截取出来

awk '{print $3}' access.log | sort | uniq -c | sort -nr | awk '$1 > 1000'


这个命令首先通过awk '{print $3}'提取每行中的第三个字段(即IP地址),然后使用sort | uniq -c对IP地址进行计数和去重,最后通过sort -nr按访问次数降序排列,并用awk '$1 > 1000'筛选出访问次数大于1000次的IP地址。





[root@master ~]# awk '{print $3}' access.log | sort | uniq -c | sort -nr | awk '$1 > 1000'
 251647 
  22877 GET
   2358 192.168.127.12
   1849 10.0.0.1
   1743 172.16.31.10
   1524 192.168.0.1



举报

相关推荐

【第一天】

第一天

作业第一天

Redis第一天

HCIP 第一天

CSS第一天

JAVA第一天

0 条评论