Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Apr 2017 15:19:19 -0500
From:      Antonio Olivares <olivares14031@gmail.com>
To:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   awk, swap elements A and B, pipe a command in place of an element
Message-ID:  <CAJ5UdcNWej7jSjMTdZf6Rmf9-EiUBroU3HzN-1EiGZx=JSB2Vw@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Dear folks,

I would like to create a table using awk and we can do this easily

awk ' { print $2 , '\t'  $1 } ' input_file

However if we have 3 elements, namely a

TimeStamp  Home Away
1                  2       3

We can swap 2 and 3 with above code.  However I want to format $1 with
date -r "$i" "+%a %b %d %Y %I:%M %p" and then swap $2 and $3.  With
regular BSD awk strftime command is not available.  We can use for
command to format the timestamp

for i in `sh formattimestamp.sh` ; do echo "$i " ; date -r "$i" "+%a
%b %d %Y %I:%M %p"

the formattimestamp.sh contains items like
echo '16801 86400 * p' | dc
echo '16804 86400 * p' | dc
echo '16808 86400 * p' | dc
etc..

this echos the timestamp and formats it.  But I would need to add
columns 2 and 3 but swapping them into place.  Without installing
gawk, and not using perl can it be done with bsd awk and /bin/sh and
how?
I have tried piping the output, but cannot get the function to work.

Thanks,


Antonio



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ5UdcNWej7jSjMTdZf6Rmf9-EiUBroU3HzN-1EiGZx=JSB2Vw>