Date: Fri, 3 Nov 2017 23:37:29 +1100 (EST) From: Ian Smith <smithi@nimnet.asn.au> To: Polytropon <freebsd@edvax.de> Cc: byrnejb@harte-lyne.ca, freebsd-questions@freebsd.org Subject: Re: Reconstruct a bash_history file Message-ID: <20171103232233.P7397@sola.nimnet.asn.au> In-Reply-To: <mailman.75.1509710402.96436.freebsd-questions@freebsd.org> References: <mailman.75.1509710402.96436.freebsd-questions@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In freebsd-questions Digest, Vol 700, Issue 5, Message: 7 On Thu, 2 Nov 2017 21:46:34 +0100 Polytropon <freebsd@edvax.de> 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 cheers, Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20171103232233.P7397>