awk COMMAND:
awk command is used to manipulate the text.This command checks each line of a file, looking for patterns that match those given on the command line.
SYNTAX:
The Syntax is
awk '{pattern + action}' {filenames}
OPTIONS:
-W version
Display version information and exit.
-F
Print help message and exit.
EXAMPLE:
Lets create a file file1.txt and let it have the following data:
Data in file1.txt
14 15 16
15 15 11
5 56 6
5 25 1
To print the second column data in file1.txt
awk '{print $2}' file1.txt
This command will manipulate and print second column of text file (file1.txt). The output will look like
15
15
56
25
To multiply the column-1 and column-2 and redirect the output to file2.txt:
awk '{print $1,$2,$1*$2}' file1.txt > file2.txt
Command Explanation:
$1
: Prints 1st column
$2
: Prints 2ndcolumn
$1*$2
: Prints Result of $1 x $2
file1.txt
: input file
>
: redirection symbol
file2.txt
: output file
The above command will redirect the output to file2.txt and it will look like,
14 15 210
15 15 225
5 56 280
5 25 125
Find LINUX Commands... Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this LINUX / UNIX cmd reference. This is a copyright content.