Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Examples of awk usage

Shulou Source: shulou.com Published: 2022-06-01 04:45:02 10月05日 Update

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

Tags: Statistics methods functions content knowledge knowledge points fields files delimiters times words addresses text numbers middle tables functions colons variables characters first time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Shulou Information Xiaomi Docker