Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of basic parameters of awk

Shulou Source: shulou.com Published: 2022-06-01 04:58:26 09月17日 Update

This article mainly shows you the "sample analysis of the basic parameters of awk", which is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and study the "sample analysis of the basic parameters of awk".

Awk is good at manipulating files one line at a time, reading one line at a time, and then acting accordingly. The basic syntax format of awk when reading a single file is awk 'BEGIN {OFS=FS= "\ t"} {print $0, $1;}' filename's syntax when reading multiple files is awk...

Awk is good at manipulating files one line at a time, reading one line at a time, and then acting accordingly.

The basic syntax format for awk to read a single file is

Awk 'BEGIN {OFS=FS= "\ t"} {print $0, $1;}' filename

The syntax when reading multiple files is

Awk 'BEGIN {OFS=FS= "\ t"} ARGIND==1 {print $0, $1;} ARGIND==2 {}' file1 file2

The command part after the awk is enclosed in quotation marks, which can be single quotation marks or double quotation marks, but be careful not to be the same as the quotation marks used in the internal command, otherwise the nearest quotation marks will be regarded as a group, causing an interpretation error.

OFS: column delimiter (output field separtor) for file output

FS: column delimiter (field separtor) when the file is imported

BEGIN: set initial parameters, initialize variables

END: do the final processing after reading the file

Other {}: loop through every line of the file

$0 represents a line of content; $1, $2, … $NF represents the first column, the second column to the last column.

How many columns are there in the NF (number of fields) file; how many lines have been read in the NR (number of rows) file: how many lines have been read in the current FNR file, which is often used in multi-file operations.

The above is all the contents of the article "sample Analysis of awk basic parameters". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: File quotation mark parameter line content grammar example analysis article delimiter single command multiple format study help same in use variable easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Technology Redmi macOS NVidia