awk, swap elements A and B, pipe a command in place of an element

Antonio Olivares olivares14031 at gmail.com
Wed Apr 12 12:32:39 UTC 2017


On Tue, Apr 11, 2017 at 6:14 PM, Karl Young <karly at kipshouse.org> wrote:
> Anton Yuzhaninov(citrin+bsd at citrin.ru)@2017.04.11 17:18:47 -0400:
>> On 04/11/17 16:19, Antonio Olivares wrote:
>> > 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
>>
>> echo "1491945088 x y" | awk '{ system("date -r "$1" \"+%a %b %d %Y %I:%M
>> %p\" | tr -d \"\n\""); print " "$3" "$2}'
>> Tue Apr 11 2017 05:11 PM y x
>>
>
> Heh heh.  Perl has no lock on TMTOWTDI
>

Thanks to both yourself and Anton for your suggestions.  This works
beautifully :)

Best Regards,


Antonio


More information about the freebsd-questions mailing list