Flash Notes

Commands - Getting the result of a command


• How to get the result of the date command from an awk program ?

Solution

Use the following syntax : command | getline;

Program

#!/bin/sh

awk 'BEGIN {
cmd = "date"
cmd | getline;
close(cmd);
date = $0;
print date;
}'

Example 1

$ ./pipe_date.awk 
Thu Oct 16 09:48:25 CEST 2014