diff --git a/README.md b/README.md index 0b362bd..94792e0 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,31 @@ -# tf - command-line time formatter +# tf - CLI Unix Time formatter -`tf` scans for epoch times in input and outputs them +`tf` scans for UNIX epoch times in input and outputs them as human readable strings to stdout. ``` $ cat log.txt [1524241219] Time is on my side [1555777220] Yes it is -[1587399621] A time in ecpoch millis: 1637419929123 -[1618935621] A time in ecpoch nanos: 1637419929123456789 +[1587399621] A time in epoch millis: 1637419929123 +[1618935621] A time in epoch nanos: 1637419929123456789 $ tf -g log.txt [12:20:19] Time is on my side [12:20:20] Yes it is -[12:20:21] A time in ecpoch millis: 09:52:09.123 -[12:20:21] A time in ecpoch nanos: 09:52:09.123456789 +[12:20:21] A time in epoch millis: 09:52:09.123 +[12:20:21] A time in epoch nanos: 09:52:09.123456789 ``` ## Usage ``` $ tf --help -usage: ./tf [file1 [file2 [...]]] +usage: tf [file1 [file2 [...]]] -Time Formatter +UNIX Time Formatter (tf) -Scans for epoch times in input and outputs them +Scans for UNIX epoch times in input and outputs them as human readable strings to stdout. 10-digits are interpreted as seconds, 13 as milliseconds, @@ -34,8 +34,8 @@ as human readable strings to stdout. If no filenames or only '-' is passed, stdin is processed. examples: -$ echo 1637421447 | tf -$ tf -g log.txt | head + $ echo 1637421447 | tf + $ tf -g log.txt | head The time formatting uses Golang Time.Format layouts: https://pkg.go.dev/time#Time.Format @@ -43,9 +43,9 @@ The time formatting uses Golang Time.Format layouts: options: -b, --block use block buffering (default: line buffering) -z, --block-size uint32 block buffer size (default 4096) - -d, --date default format with date: '2006-01-02 15:04:05' - -f, --format string golang Time.Format string (default: '15:04:05') - -g, --global global match + -d, --date output with date, same as --format '2006-01-02 15:04:05' + -f, --format string output with Golang Time.Format layout (default: '15:04:05') + -g, --global global match (default: convert only first match in line) -h, --help show help ``` @@ -71,8 +71,8 @@ Raw log: $ cat log.txt [1524241219] Time is on my side [1555777220] Yes it is -[1587399621] A time in ecpoch millis: 1637419929123 -[1618935621] A time in ecpoch nanos: 1637419929123456789 +[1587399621] A time in epoch millis: 1637419929123 +[1618935621] A time in epoch nanos: 1637419929123456789 ``` Basic usage, piping from `stdin`: @@ -80,8 +80,8 @@ Basic usage, piping from `stdin`: $ cat log.txt | tf [12:20:19] Time is on my side [12:20:20] Yes it is -[12:20:21] A time in ecpoch millis: 1637419929123 -[12:20:21] A time in ecpoch nanos: 1637419929123456789 +[12:20:21] A time in epoch millis: 1637419929123 +[12:20:21] A time in epoch nanos: 1637419929123456789 ``` Date conversion: @@ -89,8 +89,8 @@ Date conversion: $ tf -d log.txt [2018-04-20 12:20:19] Time is on my side [2019-04-20 12:20:20] Yes it is -[2020-04-20 12:20:21] A time in ecpoch millis: 1637419929123 -[2021-04-20 12:20:21] A time in ecpoch nanos: 1637419929123456789 +[2020-04-20 12:20:21] A time in epoch millis: 1637419929123 +[2021-04-20 12:20:21] A time in epoch nanos: 1637419929123456789 ```` Global match, converting sub-second times: @@ -98,8 +98,8 @@ Global match, converting sub-second times: $ tf -gd log.txt [2018-04-20 12:20:19] Time is on my side [2019-04-20 12:20:20] Yes it is -[2020-04-20 12:20:21] A time in ecpoch millis: 2021-11-20 09:52:09.123 -[2021-04-20 12:20:21] A time in ecpoch nanos: 2021-11-20 09:52:09.123456789 +[2020-04-20 12:20:21] A time in epoch millis: 2021-11-20 09:52:09.123 +[2021-04-20 12:20:21] A time in epoch nanos: 2021-11-20 09:52:09.123456789 ``` ---- diff --git a/cmd/tf/main.go b/cmd/tf/main.go index 9d9e8ca..118d659 100644 --- a/cmd/tf/main.go +++ b/cmd/tf/main.go @@ -14,9 +14,9 @@ import ( var usageFormat string = `usage: %s [file1 [file2 [...]]] -Time Formatter +UNIX Time Formatter (tf) -Scans for epoch times in input and outputs them +Scans for UNIX epoch times in input and outputs them as human readable strings to stdout. 10-digits are interpreted as seconds, 13 as milliseconds, @@ -25,8 +25,8 @@ as human readable strings to stdout. If no filenames or only '-' is passed, stdin is processed. examples: -$ echo 1637421447 | tf -$ tf -g log.txt | head + $ echo 1637421447 | tf + $ tf -g log.txt | head The time formatting uses Golang Time.Format layouts: https://pkg.go.dev/time#Time.Format @@ -91,11 +91,11 @@ func main() { var useDate bool var showHelp bool - pflag.StringVarP(&g_outputFormat, "format", "f", "", fmt.Sprintf("golang Time.Format string (default: '%s')", DEFAULT_FORMAT)) - pflag.BoolVarP(&g_globalMatch, "global", "g", false, "global match") + pflag.StringVarP(&g_outputFormat, "format", "f", "", fmt.Sprintf("output with Golang Time.Format layout (default: '%s')", DEFAULT_FORMAT)) + pflag.BoolVarP(&g_globalMatch, "global", "g", false, "global match (default: convert only first match in line)") pflag.BoolVarP(&g_blockBuffering, "block", "b", false, "use block buffering (default: line buffering)") pflag.Uint32VarP(&g_blockBufferSize, "block-size", "z", DEFAULT_BLOCK_BUFFER_SIZE, "block buffer size") - pflag.BoolVarP(&useDate, "date", "d", false, fmt.Sprintf("default format with date: '%s'", DEFAULT_FORMAT_WITH_DATE)) + pflag.BoolVarP(&useDate, "date", "d", false, fmt.Sprintf("output with date, same as --format '%s'", DEFAULT_FORMAT_WITH_DATE)) pflag.BoolVarP(&showHelp, "help", "h", false, "show help") pflag.Parse() diff --git a/log.txt b/log.txt index 3089670..7dcffe5 100644 --- a/log.txt +++ b/log.txt @@ -1,4 +1,4 @@ [1524241219] Time is on my side [1555777220] Yes it is -[1587399621] A time in ecpoch millis: 1637419929123 -[1618935621] A time in ecpoch nanos: 1637419929123456789 +[1587399621] A time in epoch millis: 1637419929123 +[1618935621] A time in epoch nanos: 1637419929123456789