Date: Tue, 11 Apr 2017 14:01:05 -0700 From: Karl Young <karly@kipshouse.org> To: Antonio Olivares <olivares14031@gmail.com> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: awk, swap elements A and B, pipe a command in place of an element Message-ID: <20170411210105.GY2787@mailboy.kipshouse.net> In-Reply-To: <CAJ5UdcNWej7jSjMTdZf6Rmf9-EiUBroU3HzN-1EiGZx=JSB2Vw@mail.gmail.com> References: <CAJ5UdcNWej7jSjMTdZf6Rmf9-EiUBroU3HzN-1EiGZx=JSB2Vw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Antonio Olivares(olivares14031@gmail.com)@2017.04.11 15:19:19 -0500: > 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. I found this works (on FreeBSD 7.2) awk '{ "date -r "$1 | getline $1 ; print $1, $3, $2 }' < input Tue Apr 11 14:20:13 PDT 2017 awaydata homedata Tue Apr 11 14:21:13 PDT 2017 moreawaydata morehomedata -karl > > Thanks, > > > Antonio > _______________________________________________ > freebsd-questions@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170411210105.GY2787>