Skip to content

Commit

Permalink
update help and fix spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
neomantra committed Apr 24, 2022
1 parent 3c40e12 commit ab00cec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <options> [file1 [file2 [...]]]
usage: tf <options> [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,
Expand All @@ -34,18 +34,18 @@ 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
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
```

Expand All @@ -71,35 +71,35 @@ 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`:
```
$ 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:
```
$ 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:
```
$ 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
```
----
Expand Down
14 changes: 7 additions & 7 deletions cmd/tf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

var usageFormat string = `usage: %s <options> [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,
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions log.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ab00cec

Please sign in to comment.