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

Regular expression tool (part two)

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Awk

Common usage of 1.awk

Typically, the command format used by awk is as follows, where single quotation marks and curly braces "{}" are used to set the processing action on the data. Awk can process the target file directly or through the "- f" read script. By default, the delimiter of the field is a space or the tab key. The result of awk execution can be printed and displayed through the function of print. In the process of using the awk command, you can use the logical operator "& &" for "and", "|" for "or", "!" It means "not"; you can also perform simple mathematical operations, such as +, -, *, /,%, ^ for addition, subtraction, multiplication, division, remainder, and multiplier, respectively.

Awk option 'mode or condition {edit instruction}' file 1 file 2 / / filter and output the contents of the file character condition

Awk-f script file 1 file 2 / / call edit instructions from the script, filter and output content

2 built-in variables

FS: specifies the field separator for each line of text, which defaults to spaces or tab stops.

NF: the number of fields in the rows currently being processed.

NR: the line number (ordinal) of the currently processed row.

$0: the entire line content of the currently processed row.

$n: the nth field (nth column) of the currently processed row.

FILENAME: the name of the file being processed.

RS: data records are separated. The default is\ n, that is, one record per behavior.

3 examples of usage

1) output text by line

Awk'{print} 'test.txt / / outputs everything, which is equivalent to cat test.txt

Awk'{print $0} 'test.txt / / outputs everything, which is equivalent to cat test.txt

Awk 'NR==1,NR==3 {print}' test.txt / / output line 1-3

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

Servers

Wechat

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

12
Report