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

How does the stream editor awk in shell work?

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "what is the working principle of the flow editor awk in shell". In the operation of actual cases, many people will encounter this dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Awk command

Awk is a language that processes text files and is a powerful text analysis tool for processing text and data under linux/unix.

Moreover, it supports advanced functions such as user-defined functions and dynamic regular expressions, and is a powerful programming tool under linux/unix.

How awk works

Read the text line by line, delimited by default with a space or tab key, save the separated fields to the built-in variables, and execute editing commands according to mode or condition.

The sed command is often used to process an entire line, while awk tends to divide a line into multiple "fields" and then process it.

The reading of awk information is also read line by line, and the execution result can be printed and displayed through the function of print. In the process of using the awk command, you can use the logical operators "&" to denote and "II" to denote "or", "!" It means "not"; you can also perform simple mathematical operations, such as +, one, *, /,%, ^ for addition, subtraction, multiplication, division, remainder, and multiplier, respectively.

Awk command format awk option "mode or condition [action]" file 1 file 2awk-f script file 1 file 2

Common built-in variables in awk (can be used directly)

The built-in variable describes the FS column separator, sets the field separator for each line of text, defaults to spaces or tabs the number of fields currently processed by NF, the number of fields currently processed by NR (ordinal) $0 the entire line content of the current processing row $n the nth field (nth column) of the current processing row the file name RS line separator processed by FILENAME, when awk reads data from the text The data will be cut into many records according to the definition of RS, while awk will read in only one record at a time for processing. The default value is\ nawk to output text on a line.

Awk'(NR > = 1) & & (NR

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

Development

Wechat

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

12
Report