Crates.io | extract |
lib.rs | extract |
version | 0.1.1 |
source | src |
created_at | 2017-03-06 22:37:53.907674 |
updated_at | 2017-03-11 11:37:00.469802 |
description | A tool for extracting text from text. |
homepage | |
repository | https://github.com/jelford/extract/ |
max_upload_size | |
id | 8865 |
size | 9,265 |
Extract text from text using a regex - a simple way to consume keyed fields from poorly-(or un-)structured text.
Extract accepts as an argument a regex with a single capture group, and will read lines from stdin, printing captured values.
> echo "hello subject=world" | extract "subject=(.+)"
world
extract
keeps reading until it reaches the end of input, processing lines one-at-a-time:
> cat multiline
Hello subject=world
Hello subject=Dorris
> cat multiline | extract "subject=(\w+)"
world
Dorris
From source:
cargo install
From crates.io
:
cargo install extract
MIT / Apache 2.
Feel free to open an issue / PR. I'd be interested in adding support for more structured outputs (e.g. JSON from a regex with named capture groups).
grep -o
?extract
only prints the catured group, not the whole match.
sed
for this?Not first time, normally. Maybe your sed-fu is better than mine. This tool was originally created when I needed to extract ids from the output of xinput --list
, in frustration after the fourth attempt to deliver the correct incantations to sed
.