Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the function of AWK in LINUX

Shulou Source: shulou.com Published: 2022-05-31 13:31:22 09月24日 Update

This article is to share with you about the function of AWK in LINUX, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article, without saying much, follow the editor to have a look.

Main functions: row fetch, column fetch, data statistics

Basic format:

Awk-F 'split character' {print $1} 'filename

2the schematic diagram of dint awk logic:

Content in the awk-BEGIN module (BEGIN'{print $1}')

Read the first line of the text (read by line)-if the output result is not satisfied, the next line continues to read until the entire text is finished.

Awk-F 'split character' {print $0} 'file name indicates that full column information is displayed

$0 represents a scalar, meaning all

Awk can also be used to find

Awk'/ character / 'file name

3. Match plus processing action

Awk also supports regularities

The difference between NF and NR (NF stores the number of columns, NR stores the number of rows)

Awk-favored etc/passwd'$1mm / ^ root/' / match ~ indicates a match

Awk-favored NF~/bash$/''$NF~/bash$/' / etc/passwd

The value of $NF refers to the last column.

The use of operators that compare sizes and equals in awk

4, example: how many ordinary users are there at present?

Statistics of disk partition usage?

Df | awk NR==2 | awk'$31000000 {print $4} 'matches the third column in the information ending with / (used has been used) and outputs its fourth column if it is greater than 1000000 (remaining available available)

5Jing awk filter ip address

6Jing awk batch create users, use dynamic passwords and save

These are the functions of AWK in LINUX. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Statistics function character file name output line information content text more user knowledge article remaining storage practical general action dynamic Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Microsoft Linux MariaDB