上QQ阅读APP看书,第一时间看更新
Extending the AWK command line on multiple lines
For short AWK programs, it is most convenient to execute them on the command line. This is done by enclosing AWK commands in single quotes. Yet at times, the AWK commands that you want to execute on the command line are longer than one line. In these situations, you can extend the AWK commands to multiple lines using \ as the last element on each line. It is also mandatory at that time to enclose AWK commands in single quotes. For example:
$ awk 'BEGIN { print "***Emp Info***" } \
> { print } \
> END { print "***Ends Here***" } ' empinfo.txt
It is the same as if we have executed the AWK command on a single line, as follows:
$ awk 'BEGIN { print "***Emp Info***" } { print } END{ print "***Ends Here***" }' empinfo.txt
The output of the previous executed AWK command is:
***Emp Info***
Jack 9857532312 jack@gmail.com hr 2000 5
Jane 9837432312 jane@gmail.com hr 1800 5
Eva 8827232115 eva@gmail.com lgs 2100 6
amit 9911887766 amit@yahoo.com lgs 2350 6
Julie 8826234556 julie@yahoo.com hr 2500 5
***Ends Here***