From owner-freebsd-questions@freebsd.org Fri Nov 3 13:50:34 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 2BE36E52B6A for ; Fri, 3 Nov 2017 13:50:34 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay14.qsc.de (mailrelay14.qsc.de [212.99.163.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass Class 2 CA" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 897BA65478 for ; Fri, 3 Nov 2017 13:50:32 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay14.qsc.de; Fri, 03 Nov 2017 14:50:29 +0100 Received: from r56.edvax.de (port-92-195-25-5.dynamic.qsc.de [92.195.25.5]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id B6FB43CC3F; Fri, 3 Nov 2017 14:50:27 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id vA3DoQbL001922; Fri, 3 Nov 2017 14:50:26 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Fri, 3 Nov 2017 14:50:26 +0100 From: Polytropon To: Ian Smith Cc: byrnejb@harte-lyne.ca, freebsd-questions@freebsd.org Subject: Re: Reconstruct a bash_history file Message-Id: <20171103145026.16c4aa5a.freebsd@edvax.de> In-Reply-To: <20171103232233.P7397@sola.nimnet.asn.au> References: <20171103232233.P7397@sola.nimnet.asn.au> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay14.qsc.de with A92F96839B2 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1628 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: Fri, 03 Nov 2017 13:50:34 -0000 On Fri, 3 Nov 2017 23:37:29 +1100 (EST), Ian Smith wrote: > In freebsd-questions Digest, Vol 700, Issue 5, Message: 7 > On Thu, 2 Nov 2017 21:46:34 +0100 Polytropon wrote: > > > You need the YYYY-MM-DD HH:MM:SS timestamp to the Epoch format, > > prefix it with a #, and put the command on a new line. > > > > Maybe like this, if you don't mind a multiple-line one-liner > > of regular shell script: > > > > $ cat history.txt | while read LINE; do DATETIME=`echo $LINE | cut -d ':' -f 1-3`; TIMESTAMP=`date -j -f "%Y-%m-%d %H:%M:%S" "${DATETIME}" "+#%s"`; COMMAND=`echo $LINE | cut -d ':' -f 4-`; echo "${TIMESTAMP}"; echo "${COMMAND}" | sed "s/^ //"; done > bash_history.txt > > > > This version is easier to read: > > > > cat history.txt | while read LINE; do > > DATETIME=`echo $LINE | cut -d ':' -f 1-3` > > TIMESTAMP=`date -j -f "%Y-%m-%d %H:%M:%S" "${DATETIME}" "+#%s"` > > COMMAND=`echo $LINE | cut -d ':' -f 4-` > > echo "${TIMESTAMP}" > > echo "${COMMAND}" | sed "s/^ //" > > done > bash_history.txt > > > > It features the "useless use of cat" line the one-liner. ;-) > > Nice work! > > A most useful "useless use of cat", but even that could be avoided with: > > while read LINE; do > [..] > done < history.txt > bash_history.txt Fully right. I thought about it after hitting "Send". Additionally, the qupting for the echo commands isn't that efficient, and I'd suggest do move the sed step to the COMMAND= line. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...