项目作者: jelford

项目描述 :
A tool for extracting text from text
高级语言: Rust
项目地址: git://github.com/jelford/extract.git
创建时间: 2017-03-06T21:57:15Z
项目社区:https://github.com/jelford/extract

开源协议:

下载


extract

Build Status
crates.io

Extract text from text using a regex - a simple way to consume keyed fields from poorly-(or un-)structured text.

Usage

Extract accepts as an argument a regex with a single capture group, and will read lines from stdin, printing captured values.

  1. > echo "hello subject=world" | extract "subject=(.+)"
  2. world

extract keeps reading until it reaches the end of input, processing lines one-at-a-time:

  1. > cat multiline
  2. Hello subject=world
  3. Hello subject=Dorris
  4. > cat multiline | extract "subject=(\w+)"
  5. world
  6. Dorris

Installation

From source:

  1. cargo install

From crates.io:

  1. cargo install extract

License

MIT / Apache 2.

Issues / Contributing

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).

FAQs

  • How is this different to grep -o?

extract only prints the captured group, not the whole match.

  • Can’t you use 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.