Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@rtspecialty.com>2017-11-22 10:23:23 -0500
committerMike Gerwitz <mike.gerwitz@rtspecialty.com>2017-11-22 13:05:02 -0500
commitdf4d976277795d06796b70043847d020c8d724aa (patch)
tree1a8b4029993847815e1a6f35764f65a1e828f568
parentbc6cd539fe4006380fc0b7c16f26a5a931d7f482 (diff)
downloadtame-df4d976277795d06796b70043847d020c8d724aa.tar.gz
tame-df4d976277795d06796b70043847d020c8d724aa.tar.bz2
tame-df4d976277795d06796b70043847d020c8d724aa.zip
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.
-rwxr-xr-xsrc/current/tools/csvm2csv38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/current/tools/csvm2csv b/src/current/tools/csvm2csv
index 3bcbc7b..1b89b5b 100755
--- a/src/current/tools/csvm2csv
+++ b/src/current/tools/csvm2csv
@@ -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
{