In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
one。 AWK description
Awk is a programming language used to process text and data under linux/unix. Data can come from standard input, one or more files, or the output of other commands. It supports advanced functions such as user-defined functions and dynamic regular expressions, and is a powerful programming tool under linux/unix. It is used on the command line, but more often as a script.
The way awk handles text and data: it scans the file line by line, from the first line to the last line, looking for lines that match a particular pattern, and doing what you want on those lines. If no processing action is specified, the matching lines are displayed to standard output (screen), and if no mode is specified, all rows specified by the operation are processed.
Awk represents the first letter of the author's last name, respectively. Because it is written by three people, namely, Alfred Aho, Brian Kernighan and Peter Weinberger.
Gawk is the GNU version of awk and provides some extensions to Bell Labs and GNU. The awk described below takes the gawk of GUN as an example. Awk has been linked to gawk in the linux system, so the following is all introduced in awk.
two。 Awk command format and options
2.1. There are two forms of awk syntax.
Awk [options] 'script' var=value file (s)
Awk [options]-f scriptfile var=value file (s)
2.2. Command option
(1)-F fs or-- field-separator fs: specifies the input file break delimiter, where fs is a string or a regular expression, such as-F:.
(2)-v var=value or-- asign var=value: assign a user-defined variable.
(3)-f scripfile or-- file scriptfile: reads the awk command from the script file.
(4)-mf nnn and-mr nnn: sets an inherent limit on the NNN value, the-mf option limits the maximum number of blocks allocated to the nnn, and the-mr option limits the maximum number of records. These two functions are extensions to the Bell lab version of awk and are not applicable in standard awk.
(5)-W compact or-- compat,-W traditional or-- traditional: run awk in compatibility mode. So gawk behaves exactly like standard awk, and all awk extensions are ignored.
(6)-W copyleft or-- copyleft,-W copyright or-- copyright: print short copyright information.
(7)-W help or-- help,-W usage or-- usage: print all awk options and a short description of each option.
(8)-W lint or-- lint: prints warnings about structures that cannot be ported to traditional unix platforms.
(9)-W lint-old or-- lint-old: prints warnings about structures that cannot be ported to traditional unix platforms.
(10)-W posix: turns on compatibility mode. However, the following restrictions are not recognized: / x, function keywords, func, escape sequence, and when fs is a space, the new line is used as a field delimiter; operators * * and * * = cannot replace ^ and ^ =; fflush is invalid.
(11)-W re-interval or-- re-inerval: allow the use of interval regular expressions, refer to (Posix character class in grep), such as the parenthesis expression [[: alpha:]].
(12)-W source program-text or-- source program-text: use program-text as the source code and can be mixed with the-f command.
(13)-W version or-- version: prints the version of the bug report information.
14. Special symbol
| * +.
Example 1: split and print the third line of 2.txt
Awk-F':'{print $3} '2.txt (- F': 'fixed format {print $3} number of lines printed)
Example 2: split and print out 5 lines of 2.txt 's 3, 4, and 4.
Awk-F':'{print $3 2.txt
Example 3: split and print out 5 lines of 2.txt 's 3 and 4 minutes, and use ":" as a separator.
Awk-F':''OFS= ":" {print $3 2.txt (the OFS command can specify a delimiter, which can be:, *)
Example 4: matches the line of root in 2.txt
Awk'/ root/' 2.txt
Example 5: lines matching root and lizheng in 2.txt
Awk'/ root | lizheng/' 2.txt
Example 6: matches the lines of sendd in 1.txt (can have more than one s or one d)
* match 0 or more characters
Awk'/ s roomdUnip '1.txt
Example 6: matches the line of sausd in 1.txt
? Match 0 or one
Awk'/ s roomdUnip '1.txt
Example 7: matches the line of sausd in 1.txt
+ match 1 or more
Awk'/ s roomdUnip '1.txt
Example 8: matches the line of s.Secretd in 1.txt
. * match as long as the first is s and the last is d
Awk'/ s.roomdUnip '1.txt
Example 9: matches the line of (ss) + in 1.txt
Awk'/ (ss) + / '1.txt
Example 10. Matches the line of sausd in the second paragraph of the 1.txt
Awk-F':'$2cm 1.txt
Example 11. Match the line in the second paragraph of the 1.txt and print only the contents of the second line
Awk-F':'$2~/s*d/ {print $2} '1.txt
Example 12. Match 2 conditions in 1.txt and print them out (the first condition is to find out and print 1 and 3 paragraphs in the first paragraph)
(the second condition is that the first matching e is found and printed 1 and 3 paragraphs) (2 rules)
Awk-F':'$1~/s*d/ {print $1 recording 3}; $1~/e/ {print $1 recording 3} '1.txt (output that meets 2 conditions will be printed twice)
Example 12: does not match the line of nologin in 2.txt
Awk-F':'$7 2.txt.
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.