awk is a text processing tool in Linux, similar to the shell programming language, has its own language, the following small series will introduce you to the use of awk text processing tools in Linux, interested Friends can come and find out.
Called
1. command
awk [-F field-separator] & lsquo; commands & rsquo; input-file (s)
commands are true awk commands, [-F field separators] are optional. Input-file(s) is the file to be processed. In awk, in each line of a file, each item separated by a domain separator is called a field. Typically, in the case of the unnamed -F domain separator, the default domain separator is a space (or tab).
2.shell script mode
Insert all awk commands into a file and make the awk program executable, then the awk command interpreter as the first line of the script, by typing the script name transfer. Equivalent to the first line of the shell script: #! /bin/sh can be replaced with: #! /bin/awk -f
3. Insert all awk commands into a single file, then call: awk -f awk-script-file input-file(s) where -f option loads awk-script The awk script in -file, input-file(s) is the same as above.
Built-in variables
ARGC: Number of command line arguments
ARGV: Command line arguments
ENVIRON: UNIX environment variables
ERRNO: UNIX system error message
FILENAME: filename of awk browse
OFMT: Number output format %.6g
FNR: Number of records for browsing files
FS: Set the input field separator, equivalent to the command line -F option
NF: The number of fields to view the record
NR: The number of records read, that is, the line Number, starting from 1
FNR: Current number of records
OFS: Output field separator
ORS: Output record separator
RS: Control record Separator
$0: Current record (as a single variable)
$1~$n: The nth field of the current record, separated by FS
Output function< Br>
print: Parameters can be variables, values or strings. Strings must be quoted in double quotes, separated by commas. Without a comma, the parameters are concatenated and cannot be distinguished. Here, the role of the comma is the same as the separator of the output file, but the latter is a space.
printf: its usage is basically similar to printf in c language, you can format the string, the output is complex , printf is easier to use, the code is easier to understand. The specific format is as follows:
%d decimal signed integer
%u decimal unsigned integer
%f floating point number
%s string
%c single character
%p pointer value
%e exponential floating point number
%x %X unsigned in hexadecimal Integer
%o Unsigned integer in octal
%g Automatically select the appropriate representation
Get external variable
1. Get normal External variables
awk ‘{action}’ variable name=variable value
2.BEGIN block variable
awk –v variable name=variable value[ –v variable 2=value 2 …] ‘BEGIN{action}’
3.Environment variables
Need to use built-in variable ENVIRON implementation
Previous123456 One page total of 6 pages
Linux system different files, have different permissions. This is for security considerations when s
Linux mint is a Linux distribution based on Debian and Ubuntu. It is now available in Linux mint17.
There are thousands of files in the computer system. If they are not classified, th
In the copying of Linux files, the copying speed is very slow when there are many files. So, is ther
Linux recovery root password two methods
Linux is a way to execute programs as other users.
Compare the role of LANG and NLS_LANG in Linux
Tips for using timed commands in Linux systems
GDB function summary in Linux system
Ubuntu how to choose IPv4 or IPv6 channel when using apt-get update
CentOS system Lighttpd installation skills
How Linux uses the kill command to force a process to terminate
Little-known Unix command inventory
Maybe you don't know the Win7 authorization information identification method
What is the reason for the automatic restart of the WinXP computer after it is turned off?
Win10 system task scheduler usage method
How to cheat winXP minesweeping game?
Win7 mouse does not listen to either respond fast or slow response how to solve
How to clear the cache in the Windows7 Ultimate system in the ie8 browser
CF September is very lucky second bomb Double good gift only waiting for you lucky