I know that awk
is a script programming language, but sometimes I get confused about when I interpret as command or as a program.
Eg. 1 - Here I interpret as a command:
awk '{print $2}' file.txt
Eg. 2 - Here I interpret as a awk program:
awk 'BEGIN {skip = 0} \
skip == 0 {if (NF == 0)
{skip = 1} \
else
{print}; \
next} \
skip == 1 {print; \
skip = 0; \
next}'
Taken from here.
The questions are:
- When awk need be interpreted as a command?
- When awk is a program?
- There's a problem call my first example as a
awk
command?
Something like:
awk '{print $2}' file.txt | awk '{FS=" "} {print 4}'
means that awk
programs can communicate using pipes?
awk
, likecat
andls
, is both a command and a program. Theawk
program/command is an interpreter for a language which, apparently, is called "AWK". The string following theawk
command -- even if it's as little as{print $2}
-- is an AWK program. If you sayawk -f foo
, then the filefoo
(or, arguably, its content) is an AWK program. And yes, just like (most) other commands/programs,awk
processes can have their I/O redirected to files and pipes.