awktutorial/01-essence-of-awk.awk

31 lines
1.2 KiB
Awk
Executable File

#!/usr/bin/awk -f
# https://www.grymoire.com/Unix/Awk.html
# awk (named for its creators aho, weinberger and kernighan) takes a a text
# file as input. the awk program then processes that file line by line.
# think of the awk program as performing some process for each line in the file.
# or, think of an awk program as a big loop in which you define how to process
# lines of input, one line per loop iteration.
# the simplest awk program has the following structure:
# PATTERN { ACTION }
# ...where PATTERN is a text pattern that is to be matched in each successive
# line of input, and ACTION is the code to execute if the match is successful.
# the simplest possible PATTERN to match is nothing. it matches everything.
# the following valid awk script will print each line that it matches, meaning
# that it will print everything. whatever file you pipe into it will be printed
# back, line by line.
{ print }
# an easy way to test this script is as follows (minus the greater-than sign):
# > ./01.awk /etc/passwd
# NOTE: see the shbang line? notice the "-f" after the awk filepath? that needs
# to be there if you're piping a text file into an awk script. by contrast, see
# script 00.awk which does not take a file as input and does not need the -f