From owner-freebsd-questions@freebsd.org Tue Apr 11 21:28:56 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 49F2AD3A0F5 for ; Tue, 11 Apr 2017 21:28:56 +0000 (UTC) (envelope-from karly@kipshouse.net) Received: from mgmt.ironboy.kipshouse.net (ironboy.kipshouse.net [IPv6:2001:470:835a:4242::42]) (using TLSv1.2 with cipher RC4-SHA (128/128 bits)) (Client CN "mx.kipshouse.net", Issuer "Starfield Secure Certificate Authority - G2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 07861CBB for ; Tue, 11 Apr 2017 21:28:55 +0000 (UTC) (envelope-from karly@kipshouse.net) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=kipshouse.org; i=@kipshouse.org; q=dns/txt; s=kh-ss; t=1491946136; x=1523482136; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; z=Date:=20Tue,=2011=20Apr=202017=2014:01:05=20-0700|From: =20Karl=20Young=20|To:=20Antonio=20O livares=20|Cc:=20FreeBSD=20Quest ions=20|Subject:=20Re:=20a wk,=20swap=20elements=20A=20and=20B,=20pipe=20a=20command =20in=20place=20of=20an=20element|Message-ID:=20<20170411 210105.GY2787@mailboy.kipshouse.net>|References:=20|MIME-Version:=201.0|In-Reply-To:=20; bh=wPw9wA+g5FfNLS6Vq/yj162Im5h3brRXaB4bpUGkRXE=; b=QXItWX98jrHvAHsWwlovOmkUYepPML6ij5wY02UGtMG1vFJAS9Uowz0s qRAlq19bRS3q7WNs6p0y2tZJKstLYd8nlXPPLvRFwfTiWjfl9SJOKz+8L O+/rQ28LRk5z6h5FihiyXAs7rNr+qMdVgYkj9y3+vl7ojJaPlO6E8ztNV 7+HQKFnOK6CPIhgEkdD/zrDhUsXLJmRZqFOMJopzHcBavvMAsmPD6Gex1 u2xUqG4pg1ngEYMVwNbFBoKmz7cx3QutgKexyJcpRu8spbxyxlnhz+W61 xWZKj7NUOOzkW0aBv6aiGBPaLl4y2w4lL+/7xaSYXFOeKPBnkKx9BBUbA w==; Authentication-Results: d2.ironport.kipshouse.net; dkim=none (message not signed) header.i=none; spf=None smtp.pra=karly@kipshouse.org; spf=None smtp.mailfrom=karly@kipshouse.net; spf=None smtp.helo=postmaster@mailboy.kipshouse.net Received-SPF: None (d2.ironport.kipshouse.net: no sender authenticity information available from domain of karly@kipshouse.org) identity=pra; client-ip=2001:470:835a:1010::26; receiver=d2.ironport.kipshouse.net; envelope-from="karly@kipshouse.net"; x-sender="karly@kipshouse.org"; x-conformance=sidf_compatible Received-SPF: None (d2.ironport.kipshouse.net: no sender authenticity information available from domain of karly@kipshouse.net) identity=mailfrom; client-ip=2001:470:835a:1010::26; receiver=d2.ironport.kipshouse.net; envelope-from="karly@kipshouse.net"; x-sender="karly@kipshouse.net"; x-conformance=sidf_compatible Received-SPF: None (d2.ironport.kipshouse.net: no sender authenticity information available from domain of postmaster@mailboy.kipshouse.net) identity=helo; client-ip=2001:470:835a:1010::26; receiver=d2.ironport.kipshouse.net; envelope-from="karly@kipshouse.net"; x-sender="postmaster@mailboy.kipshouse.net"; x-conformance=sidf_compatible X-SBRS: None X-MID: 243216 X-RemoteIP: 2001:470:835a:1010::26 X-RemoteHost: 2001:470:835a:1010::26, mailboypriv.kipshouse.net X-IronPort-AV: E=McAfee;i="5800,7501,8495"; a="243216" Received: from mailboypriv.kipshouse.net (HELO mailboy.kipshouse.net) ([IPv6:2001:470:835a:1010::26]) by d2.ironport.kipshouse.net with ESMTP; 11 Apr 2017 14:28:55 -0700 Received: by mailboy.kipshouse.net (Postfix, from userid 500) id CF89943B3C; Tue, 11 Apr 2017 14:01:05 -0700 (PDT) Date: Tue, 11 Apr 2017 14:01:05 -0700 From: Karl Young To: Antonio Olivares Cc: FreeBSD Questions Subject: Re: awk, swap elements A and B, pipe a command in place of an element Message-ID: <20170411210105.GY2787@mailboy.kipshouse.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Arbitrary-Number-Of-The-Day: 42 X-URL: http://www.kipshouse.org/karly X-Work-URL: http://www.cisco.com/ X-Disclaimer: My opinions do not necessarily represent those of my employer. User-Agent: Mutt/1.5.20 (2009-12-10) 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 21:28:56 -0000 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"