In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains the "awk use example analysis", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "awk use example analysis" bar!
Awk is a powerful text analysis tool.
Awk gets its name from the initials of its founders Alfred Aho, Peter Weinberger and Brian Kernighan. In fact, awk does have its own language, the awk programming language, which the three creators have officially defined as a "style scanning and processing language". It allows you to create short programs that read input files, sort data, process data, perform calculations on input, generate reports, and countless other functions.
-F specifies the delimiter instead of the default white space (space or tab)
-v specify variable
-f specify the file name of the script, that is, put the script into a file to avoid too long awk writing, visual impact, and repetitive writing
The BEGIN keyword executes the specified script segment once
A script segment defined by the END keyword, after all operations are completed
The script section that processes the data is defined in the second program
+ +-increase and decrease (front or rear)
^ * Index (right associativity)
! +-No, one dollar plus sign, one dollar minus sign
* /% multiplication, division, remainder
+-add and subtract
< >= compare
& & logical AND (abbreviated)
| | logical OR (abbreviated) |
Ternary conditional formula
= + =-= / =% = ^ = * = assignment (right associativity)
$is followed by a number to get the field of the specified column, and 0 means to fetch the whole record
Number of ARGC command line parameters
ARGV command line arguments form a Hu array
The file name of the current input file for FILENAME
FS sets the input field separator, which is equivalent to the command line-F option
OFS output domain delimiter
RS control record delimiter
ORS output record delimiter
Number of fields for NF browsing records
Number of records read by NR
The function of FNR is similar to that of NR, except that every time awk opens a new file, FNR accumulates again from 0.
Whether IGNORECASE ignores case
Record defaults to each line because the record separator (RS) is a newline character
The field defaults to each word because the domain separator (FS) is a space
Awk makes command-line arguments available through built-in variables ARGC (parameter count) and ARGV (parameter vector, or parameter value).
Cat showargs.awk BEGIN {print "ARGC=", for 0; k > > the redirect symbol needs to be enclosed with "" when it is used as a file name parameter. Getline can be used for input redirection to obtain input information awk 'BEGIN {"date" | getline date. Print "The date is", date > "date.file"} 'cat date.file# The date is Wed Dec 28 18:43:39 HKT 2016 pipeline # (b) awk' / note/ {print $0 | "grep 2499"} 'mi_info# minote3-1 5.5 "660 6G 64G 3500mAh 2499 pipeline # (c) system function. You can call awk 'BEGIN {system ("whoami")}' # root## (d) printf to format the output information, similar to awk 'BEGIN {printf "Hello,% s, you are% d years old.\ n", "Nicol TAO", "23"}' # Hello, Nicol TAO, you are 23 years old.
If the processing logic is complex, write the code into a file and reference it through-f; this prevents you from typing the wrong code.
Flexible call system commands, built-in variables to make the code more concise.
When dealing with large files, more audit and optimization of logic code can effectively improve the efficiency of execution.
Thank you for your reading, the above is the content of "awk use example analysis", after the study of this article, I believe you have a deeper understanding of the problem of awk use example analysis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.