March 2018
Beginner to intermediate
416 pages
9h 24m
English
FILENAME is set each time a new file is read. It stores the name of the current input file being read. This can be used when multiple files need to be parsed by AWK. When no data files are given on the command line, AWK reads from stdin and FILENAME is set to "-". In that case, you have to enter records in standard input, and once you are done, press Ctrl + C to stop reading from stdin. Let us begin with a very basic example:
$ awk 'END{print FILENAME}' cars.dat
The output of the execution of this command is as follows:
cars.dat
Now we will process the two files, cars.dat and emp.dat, and print some data from these files, as follows:
$ vi filename.awk#!/usr/bin/awk -fBEGIN { f1=""; f2=""; }{if ( FILENAME == "cars.dat" ){print NR, ...Read now
Unlock full access