csvm2csv: Add support for date->ts conversion
* src/current/tools/csvm2csv: Modify example to include date. (rangeout, parseLine): Renamed from `rangeout'. Add date->timestamp parsing.master
parent
bc6cd539fe
commit
df4d976277
|
@ -28,24 +28,24 @@
|
|||
#
|
||||
# For example:
|
||||
# :foo=1--3
|
||||
# $foo;7;9--10:$foo, 5--10
|
||||
# $foo;7;9--10:$foo, 5--10,1/1/2017
|
||||
#
|
||||
# Would generate:
|
||||
# 1, 5
|
||||
# 1, 6
|
||||
# 1, 5, 1483246800
|
||||
# 1, 6, 1483246800
|
||||
# ...
|
||||
# 5, 10
|
||||
# 2, 5
|
||||
# 5, 10, 1483246800
|
||||
# 2, 5, 1483246800
|
||||
# ...
|
||||
# 9, 5
|
||||
# 9, 5, 14832468005
|
||||
# ...
|
||||
# 1, 5
|
||||
# 1, 6
|
||||
# 1, 5, 1483246800
|
||||
# 1, 6, 1483246800
|
||||
# ...
|
||||
##
|
||||
|
||||
|
||||
function rangeout( i, m, j, me, orig )
|
||||
function parseline( i, m, j, me, orig )
|
||||
{
|
||||
if ( i > NF )
|
||||
{
|
||||
|
@ -55,16 +55,23 @@ function rangeout( i, m, j, me, orig )
|
|||
|
||||
orig = $i
|
||||
|
||||
if ( match( $i, /^([0-9]+\/){2}[0-9]+$/, m ) )
|
||||
{
|
||||
cmd = "date --date=" $i " +%s"
|
||||
cmd |& getline $i
|
||||
close(cmd)
|
||||
}
|
||||
|
||||
# check first for delimiters
|
||||
if ( match( $i, /^([^;]+);(.*)$/, m ) )
|
||||
{
|
||||
# give it a shot with the first value
|
||||
$i = m[1]
|
||||
rangeout( i )
|
||||
parseline( i )
|
||||
|
||||
# strip off the first value and process with following value(s)
|
||||
$i = m[2]
|
||||
rangeout( i )
|
||||
parseline( i )
|
||||
|
||||
# we've delegated; we're done
|
||||
$i = orig
|
||||
|
@ -85,12 +92,12 @@ function rangeout( i, m, j, me, orig )
|
|||
do
|
||||
{
|
||||
$i = j
|
||||
rangeout( i + 1 )
|
||||
parseline( i + 1 )
|
||||
} while ( j++ < me )
|
||||
}
|
||||
else
|
||||
{
|
||||
rangeout( i + 1 );
|
||||
parseline( i + 1 );
|
||||
}
|
||||
|
||||
# restore to original value
|
||||
|
@ -115,9 +122,8 @@ BEGIN {
|
|||
next
|
||||
}
|
||||
|
||||
# lines containing ranges (denoted by `--', the en dash, which is a typesetting
|
||||
# convetion for ranges), sub-delimiters, or variables must be expanded
|
||||
/--|;|\$[a-zA-Z_-]/ { rangeout( 1 ); next; }
|
||||
# lines that need any sort of processing (ranges, dates, etc)
|
||||
/--|;|\$[a-zA-Z_-]|\// { parseline( 1 ); next; }
|
||||
|
||||
# all other lines are normal; simply output them verbatim
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue