4
4
[ ![ Crates.io] ( https://img.shields.io/crates/v/grits.svg )] ( https://crates.io/crates/grits )
5
5
[ ![ Crates.io] ( https://img.shields.io/crates/d/grits )] ( https://crates.io/crates/grits )
6
6
7
- ` grits ` is a minimal, simple, easy-to-use line text-processor that applies regular expressions with named captures to input lines
7
+ ` grits ` is a minimal, simple, and easy-to-use line text-processor that applies regular expressions with named captures to input lines
8
8
and transforms them using a custom template string. It allows for efficient parsing, extracting, and formatting of text,
9
9
including support for colorization and other attributes you'd get using ANSI escape sequences.
10
10
11
- The following example demonstrates how to apply ` grits ` to ` tcpdump ` to extract a packet's source IP address:
11
+ The following example demonstrates how to apply ` grits ` to ` tcpdump ` to extract a packet's source ( ` src ` ) and destination ( ` dst ` ) IP address:
12
12
13
13
``` bash
14
- tcpdump | grits -p ' ^(?<ts>[^ ]+)' \
14
+ sudo tcpdump -nn | grits -p ' ^(?<ts>[^ ]+)' \
15
15
-p ' IP\w? (?<src>[^ ]+)' \
16
- -t ' [${(cyan|bold):ts}] ${(green|underlined):"src"}=${src || "NOMATCH"} '
17
-
16
+ -p ' > (?<dst>[^ ]+): ' \
17
+ -t ' [${(cyan|bold):ts}] ${(green|underlined):"src"}=${src} ${(yellow|underlined):"dst"}=${dst} '
18
18
```
19
19
20
20
![ demo image] ( images/demo.png )
21
- The left pane in the above screenshot is the raw output of ` tcpdump ` while the right pane shows the output being piped into ` grits ` .
21
+ The top pane in the above screenshot is the raw output of ` tcpdump ` while the bottom pane shows the output being piped into ` grits ` .
22
22
23
23
## Table of Contents
24
24
@@ -49,7 +49,8 @@ Arguments:
49
49
Options:
50
50
-p, --pattern <PATTERN> A regular expression with named captures. Can be specified multiple times
51
51
-t, --template <TEMPLATE> A template string that defines how to transform a line input. See long '--help'
52
- --line-buffered Force output to be line-buffered. By default, output is line buffered when stdout is a terminal and block-buffered otherwise
52
+ -r, --require <REQUIRE> Name of capture that must have at least one match for the output to show. Can be specified multiple times
53
+ --line-buffered Force output to be line-buffered. By default, output is line buffered when stdout is a terminal and block-buffered otherwise
53
54
-c, --completions <COMPLETIONS> Produce completions for shell and exit [possible values: bash, elvish, fish, powershell, zsh]
54
55
-h, --help Print help (see more with '--help')
55
56
-V, --version Print version
@@ -68,13 +69,13 @@ cargo install grits
68
69
### cURL
69
70
70
71
``` bash
71
- curl --proto ' =https' --tlsv1.2 -LsSf https://github.com/solidiquis/grits/releases/download/v0.1 .0/grits-installer.sh | sh
72
+ curl --proto ' =https' --tlsv1.2 -LsSf https://github.com/solidiquis/grits/releases/download/v0.2 .0/grits-installer.sh | sh
72
73
```
73
74
74
75
### Powershell
75
76
76
77
``` bash
77
- powershell -ExecutionPolicy Bypass -c " irm https://github.com/solidiquis/grits/releases/download/v0.1 .0/grits-installer.ps1 | iex"
78
+ powershell -ExecutionPolicy Bypass -c " irm https://github.com/solidiquis/grits/releases/download/v0.2 .0/grits-installer.ps1 | iex"
78
79
```
79
80
80
81
### Manual installation
@@ -94,7 +95,7 @@ echo 'level=info msg=foobar path=/baz' | grit -p 'msg=(?<log>[^ ]+)' -o 'transfo
94
95
```
95
96
96
97
In this command, we use a regular expression to capture the value associated with the msg field.
97
- The capture group is named log. The template string ` transformed=${log} ` will replace ` ${log} ` with
98
+ The capture group is named ` log ` . The template string ` transformed=${log} ` will replace ` ${log} ` with
98
99
the value captured from the input. The output will then be:
99
100
100
101
```
0 commit comments