Common awk commands (for conversion) and awk commands
Awk usage: awk 'pattern' {action }'Variable name meaningNumber of ARGC command line VariablesARGV command line meta ArrayFILENAME current input file nameNumber of records in the current FNR FileThe input field delimiter of FS. The default Delimiter is a space.RS inp
All users who are familiar with linux know that linuxshell is very powerful in text processing. all users who are familiar with linux know that linux shell is very powerful in text processing. There is a powerful set of text processing tools: grep, sed, awk. Grep is often used for searching and matching texts, sed is used for text editing and replacement, and awk is also the most powerful. it is often used
Previous
We all know that Linux Shell is very powerful in text processing. There is a powerful set of text processing tools: grep, sed, awk. Grep is often used for searching and matching text and SEDCompositionThis edited replacement and awk are also the most powerful and often used for report generation! The processing efficiency is very high. A file of several hundred MB can also be completed in seconds!
Awk built-in Function Analysis and awk built-in functionsI. mathematical functions
The following arithmetic functions perform the same operations as child routines with the same name in C:
Function Name
Description
Atan2 (y, x)
Returns the arc tangent of y/x.
Cos (x)
Returns the cosine of x. x is a radian.
Sin (x)
Returns the sine of x, which is a radian.
Linux Shell programming awk and linuxshell programming awk
Awk [-field-separator] 'commands' input-file (s)
Basic Mode
Awk-F ':'...
Use # to separate
Awk '{print $0}' a.txt
Print all
Awk '{print $1, $3}' a.txt
Print 1s
Linux shell sed awk command (2)-awkawk syntax Format:awk [Options]-F program-file [--] file ...Options:-F FS,--field-separator FSCreate a delimiter with FS as the input line (the default delimiter is a space or tab)-V Var=val,--assign var=valBefore executing the procedure, set a var value of Val-F program-file,--file Program-fileRead the awk instruction from the script file to replace the input processing s
Invoking awk in a shell script is very natural and simple, so let's look at awk calling the shell and passing the variable to the Shell,awk using the variables in the shell, awk passing the value to the shell variable
Invoking awk in a shell script is very natural and sim
One, what is awk
awk is a command under Linux, his output of other commands, the processing of the file is very powerful, in fact, he is more like a programming language, he can customize variables, conditional statements, there are loops, there are arrays, there are regular, there are functions, and so on. He reads the output, or file The way is a row, read a line, according to the conditions you give to
11 shell command awk, 11shell command awk
Awk, as an amazing command, can help us solve seemingly complex and difficult problems in minutes.
Awk, as its name implies (I am so embarrassed ). is a tool for processing text lines. just kidding, this command cannot be the name suggests. it is said to be the first letter of
AWK resolution, awk resolutionCut command limitations
Df-h | cut-d ""-f 5/etc/passwd
The cut command cannot correctly intercept the content with spaces as the separator.
AWK format
Awk 'condition 1 {Action 1} condition 2 {Action 2 }... 'Filename'
Condition (Pattern) [relational expressions are generally used as cond
Awk string truncation, awk string1) how to split the current string with $0, for example:Cat num.2012032911 | awk '{print $2}' | awk '{split ($0, B, "."); print B [2]}' | cut-c 3-Obtain the second column. For example, if the second column is com. sb3456.you, you can obtain sb3456 from the current split string, and the
Printf- Align LeftWidth Field step, 0 for 0 step. Prec The maximum string length, or the number of digits to the right of the decimal%c ASCII characters%d integral type%e Scientific Counting method%f floating point type%g awk determines which floating-point number is converted to E or F%o octal%s string%x HexExample one:i161 Admin # df-th|awk ' {print $1,$5} 'Filesystem AvailRootfs 23G/dev/root 23GTmpfs 16G
Awk notes, awk learning notesAwk:
Awk names: The abbreviations of the three people: Aho, (Peter) weberger and (Brain) Kernighan;
In-row fields can be processed during row processing. This is not allowed by grep/sed. In special cases, $0 is used to indicate the row;
Usage: awk [-F re] [parameter...] ['prog'] [-f pro
The problem of passing parameters in awk has always been a headache for many people. The following is a summary:
I. Direct call of awk scripts .
For example, the following script requires the calculation of the total number of logs on the 15th to 30th. $3 indicates the domain that distinguishes the encoding of different pages. The script is as follows:
#/Bin/sh;Page = $1;I = 15;While test $ I-le 30Do#
Awk array statistics, awk Array
Process the following file content, retrieve the domain name andDomain Name countSorting: (Baidu and sohu interview questions)
1 http://www.etiantian.org/index.html2 http://www.etiantian.org/1.html3 http://post.etiantian.org/index.html4 http://mp3.etiantian.org/index.html5 http://www.etiantian.org/3.html6 http://post.etiantian.org/2.html
Results:
mp3.etiantian.org 1post.etian
-font-family:"Times New Roman";mso-hansi-font-family:"Times New Roman";mso-ansi-language:#0400;mso-fareast-language:#0400;mso-bidi-language:#0400;}-->
1. Introduction
Retrieve various types of data from the original data file, remove the header, and output it to different files named according to the data type. This sorting and formatting task is a basic part of data analysis and processing. You can use awk, grep/SED/
A regular expression: a regular expression (or regular expression, called re) is a text pattern consisting of ordinary characters (such as characters A through Z) and special characters (called metacharacters). This pattern describes one or more strings to match when looking up a text body. A regular expression, as a template, matches a character pattern to the string you are searching for. Simply put, the regular expression is the method of processing the string, it is the behavior unit to cond
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.