Today a dear friend of mine needed to add a column to some files she was analyzing getting them out of the mess of MS excel and inside the thin and nice gnuplot.
The date column required a nice format : gg/mm/yy:hh.mm
So she asked me to spend a couple of min to help her in a dirty and quick way which follows:
- First of all I thought to generate epoch of the starting date and last one so to deal with seconds and easily increment them of a fixed amounf (3600sec = 1hour)
START=`date -d "12/6/2005 16:00" +%s`
LAST=`date -d "12/31/2006 16:00" +%s`;echo $LAST
DELTA=3600
- then generate the dates in epoch and convert in the desired format from cmd line
for ((i=$START; i<=$LAST; i+=$DELTA)); do date -d @$i +%d/%m/%Y:%H.%M;done >dates.dat
- check if the lenght is the same as data file with wc
- Last to merge with the data file
hope this could be helpfulpaste dates.dat data.dat >final.dat
alex
http://lxphotostudio.mine.nu
This comment has been removed by the author.
ReplyDeletebug (there are repeated entries in dates and one impossible to create)
ReplyDeleterespectively use:
$ uniq -d
$ date -d "03/26/2006 2:00" +%s
date: invalid date `03/26/2006 2:00'
just in case to add a delimiter use the following :
ReplyDeletein this case ";"
nawk -v OFS=";" '$1=$1' filename