awk
commandAwk
is a general-purpose scripting language used for advanced text processing. It is mainly used as a reporting and analysis tool. Unlike most other procedural programming languages, Awk
is data-driven, meaning that you need to define a set of operations to be performed on the input text and then it fetches the input data, processes it, and sends the results to standard output.
-F fs
: Set the input field separator to the regular expression fs
.-v var=value
: Assign the value to the variable var
before executing the awk
program.'prog'
: The awk
program.-f progfile
: Specify the file progfile
that contains the awk
program to be executed.file ...
: Files to be processed by the specified awk
program.Suppose the example file example.txt
contains the following data:
Print the third field of example.txt
.
Match the groups that start with R
using regular expressions.
Use BEGIN
and END
to perform actions before and after processing records. The process is to output groups where the second field contains Tor
.