O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The system (command) function

The system function is used to execute any operating system command and then return back to the AWK program. It returns the exit status of the program. If the command is executed successfully, we get the return value of 0. If a nonzero value is returned, this indicates the failure of the command execution. Using the system command, we can pass any shell command as an argument, and it will get executed exactly as given on the command line and the output will be returned on screen.

The following example illustrates how the system function works:

$ awk 'BEGIN { system("pwd")}'

The output of the execution of the previous code is as follows:

/home/shiwang/Desktop/

In the next example, we print the system date with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required