From owner-freebsd-questions@freebsd.org Tue Apr 11 20:19:21 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 20664D3AAA5 for ; Tue, 11 Apr 2017 20:19:21 +0000 (UTC) (envelope-from olivares14031@gmail.com) Received: from mail-ua0-x231.google.com (mail-ua0-x231.google.com [IPv6:2607:f8b0:400c:c08::231]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D16C61FA0 for ; Tue, 11 Apr 2017 20:19:20 +0000 (UTC) (envelope-from olivares14031@gmail.com) Received: by mail-ua0-x231.google.com with SMTP id a1so5100110uaf.3 for ; Tue, 11 Apr 2017 13:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=E23Y30z2j1gi7+eh/P0sntossoPwp+kmwJeBAYfAC+4=; b=dSBBHc0iXQxBNrQUFLizW7CQ03j8nVRYL1SE9c17O10+4Zwc/pQa+PnhZ6E6xIYpqv oW/HnA+ba/dSCllqOmo5T7dcNr+x5pObXvFRBFVl1Ep1yNBXnzLUYvhiBiRTGHd2f9s6 vCp7hJTFZBNYVu8NLTnpIF1ol1LCXQ0wDZbYf7riGo51YXbwA9RwemUqwzFHTuEh7jCo jowYxOqxe/2eGD9j9hNAAYSTNIkqDiMK1V8zUQ2L7dfolusNI5pHHty2vg7ycoa0KRuD ih2EVX61Dz6qEnIXBrBCs37eX4sOfO9ZnZK+n5lcVNpNevZwZswdvLnq80sjEoJ0l/QE 5sAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=E23Y30z2j1gi7+eh/P0sntossoPwp+kmwJeBAYfAC+4=; b=LqxqrO7bhMWXDGg4dk7vai/DtXm2yW5y6ZCXPziZzM8dx45qeK3uuQTqJVHl6Nqf3t rNxDpL87W5hd1LqSuNRMzMk1Td+qu4SqD/3Mdvbfs1wfHXRbW8TW/HCsMwJyKV5NYXTx 1syKQiNiS41pu3ifrYglSChF0rMbEJymnaxFAi/wSx7R7E39HZXjMm2n5p4OiCNd+x4v de6kFs2ar5SvfGXl3SjHxsVhysae474nO59GvicwB1uy2H4kADhOEcmGEqEV0ANTOrX1 pVc61raYgWeV958Z3DTPcqq54n6F7dyAAlQSjiZQjQMKoxxsj2WH+Xyc6htfe5oz/mAP w2sg== X-Gm-Message-State: AFeK/H0TfLzYIXZCG6LozADr6vhZqpS25HvPUOFQbbTovvLWK7VFsn0oC14Gf15pqzes1J0BAq0kDkvhOTFUlQ== X-Received: by 10.176.91.8 with SMTP id u8mr19418907uae.150.1491941959831; Tue, 11 Apr 2017 13:19:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.159.34.131 with HTTP; Tue, 11 Apr 2017 13:19:19 -0700 (PDT) From: Antonio Olivares Date: Tue, 11 Apr 2017 15:19:19 -0500 Message-ID: Subject: awk, swap elements A and B, pipe a command in place of an element To: FreeBSD Questions Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 Apr 2017 20:19:21 -0000 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