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

Anton Yuzhaninov citrin+bsd at citrin.ru
Tue Apr 11 21:18:59 UTC 2017


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



More information about the freebsd-questions mailing list