A simple streaming editor like sed and the like, but written in Go and expr.
Each record (depending on the file type, it can be a line(string
) / row([]string
) / json element(map[string]any
)) is read into var x
and can be referenced in the expression. By default it operates in filter
mode, which simply prints the record if the expression evaluates to true.
gedi -f examples/lines.txt 'atoi(x) % 2 == 0'
Additional vars / functions:
-
ix
: the current record number. -
x
: the current record. Whenfiletype
isline
, it's the current line asstring
, whenfiletype
iscsv
, it's the current row as[]string
. -
kx
: ifx
comes from an array of a json field,kx
is the name of the field. e.g. for{"k": [1,2,3]}
,kx
would bek
. -
now
:time.Now()
at the start of the program, provided to avoid callingtime.Now()
repeatedly in large files. -
ms
: 1time.Millsecond
-
sec
: 1time.Second
-
min
: 1time.Minute
-
hour
: 1time.Hour
-
day
: 24time.Hour
-
week
: 7 * 24time.Hour
-
month
: 30 * 24time.Hour
-
year
: 365 * 24time.Hour
-
localtime(string)
: guess time from a given string as if it's a local time. e.g. assuming local is HTK,"2023-01-01 00:00:00 WARN foobar" | localtime()
gives2023-01-01 00:00:00 UTC+08:00
-
utctime(string)
: guess time from a given string as if it's a UTC time. e.g."2023-01-01 00:00:00 WARN foobar" | utctime()
gives2023-01-01 00:00:00 UTC+0000
-
tztime(string, string)
: guess time from a given string as if it's a given timezone time. e.g."2023-01-01 00:00:00 WARN foobar" | tztime("UTC+8")
gives2023-01-01 00:00:00 UTC+08:00
-
unixtime(int64)
: converts a given unix timestamp in milliseconds, seconds, microseconds totime.Time
. -
within(time.Time|string, time.Time|string)
: checks if a given time is within a given duration comapred tonow
. e.g. find log lines that are within the last 24 hours:x[0:20] | localtime() | within("-24h")
-
after(time.Time|string, time.Time|string)
: checks if the 1st time on or after the 2nd time. -
before(time.Time|string, time.Time|string)
: checks if the 1st time on or before the 2nd time. -
gt
,lt
,ge
,le
: check if the 1st arg(ints, floats,time.Time
,time.Duration
) is greater than, less than, greater than or equal to, or less than or equal to the 2nd arg (of the same type). -
grep(input, regex [, group])
: grep matches frominput
. If theregex
has groups, thegroup
is the index of the group to return.
[x] supports line by line files
[x] supports csv
[x] supports jsonl
[x] supports jsonarray