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

Linux Command Learning Manual-awk

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Awk 'condition type 1 {action 1} condition type 2 {action 2}.' Filename

Function

Rather than sed, which often acts on an entire row, awk tends to split a row into several "fields".

Describe the processing flow of awk

Read the first line and fill in $0, $1, $2. . Among the equal variables

Judge whether the following "action" is needed according to the limitation of "condition type".

Finish all the actions and condition types

If there are subsequent "rows" of data, repeat the steps 1-3 above until all the data has been read.

After this step, you will know that awk is a "one-time processing unit of behavior" and "the smallest processing unit is field."

Commonly used variables (variable names represent meaning)

Total number of fields per row ($0) of NF

NR awk is currently dealing with the "number of rows" data

The current delimited character of FS. The default is the space bar.

The variable name for each field in each line is $1, $2. Wait. There is one exception, which is that $0 means a whole line.

Note that all subsequent actions of awk are enclosed in', so if the content is to be printed in print, remember that the invariant text, in the format mentioned by printf, needs to be in double quotes.

Logical operation symbol

Greater than

< less than

= greater than or equal to

= 2 for the next action, use total =... That instruction specifies the summation, and then the output is formatted with printf; when formatting the output,\ n must be added in the format setting of printf before the branch can be done; unlike the variable of bash shell, in awk, the variable can be used directly without the $symbol (such as total).

Other

Reference: "Brother Bird's private dishes"

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

Servers

Wechat

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

12
Report