awk script help

Hi

I'm running a command and piping it to awk.
I need to pass one of the variables to a date command

ex: cat file|awk {'print $1'} 

I need to pass the $1 the date command

somewhat hard to underhand the "ask", but....
Have you tied searching these forums?
Also look at the bottom of this thread for hints in the "More UNIX and Linux Forum Topics You Might Find Helpful" section...

Hi,

One way to do this would be to take the output of your awk command, and directly use that via command substitution as input for the date command to work on.

In the following example, we have a file containing UNIX timestamps. We want to convert those timestamps to human-readable dates. So we read in each line of the file, get our timestamp, and pass it to the date command.

$ cat date.txt
Timestamp 1561734809
Timestamp 1561734820
Timestamp 1561734842
$ cat timestamp.sh
#!/bin/bash
for timestamp in `/bin/cat date.txt | /usr/bin/awk '{print $2}'`
do
        /usr/bin/date -d @"$timestamp"
done

$ ./timestamp.sh
Fri Jun 28 16:13:29 BST 2019
Fri Jun 28 16:13:40 BST 2019
Fri Jun 28 16:14:02 BST 2019
$ 

Note that this example assumes you are using Bash as your shell - if you're using something different, then please provide full information on the nature of your environment.

Hope this helps !