Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Examples of awk usage

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

1. Count the number of occurrences of each number in the following text

[liuwei@test tmp] $cat 1.log 1 22 33 4100 1 100 100 [liuwei@test tmp] $awk'{for (iTun1) I = "20:00:00" & & $3 = "20:00:00" & & $3 / {print $5}'| awk-F:'{s [$1] + +} END {for (key in s) print key,s [key]}'# method 2, using the split function-- > you need to know what each parameter of the split function means. This method looks very high-end netstat-tan | awk'/ ^ tcp\ > / {split ($5line IP, ":") S [ip [1]] + +} END {for (key in s) print key,s [key]} 'knowledge points: the use of the split function in awk, which in this case indicates that the contents of $5 are separated by colons and stored in the ip array

7. The data in file an is required to replace the word xxx in file b in turn.

[liuwei@test tmp] $cat a

Aaa

Bbb

Ccc

Ddd

[liuwei@test tmp] $cat b

111 xxx

222 xxx

333 xxx

444 xxx

# method 1, use getline function to implement [liuwei@test tmp] $awk'{getline I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report