Skip to content
/ rew Public

A text processing CLI tool that rewrites FS paths according to a pattern.

License

Notifications You must be signed in to change notification settings

jpikl/rew

 
 

Repository files navigation

rew

The Swiss Army Knife of line-oriented text processing.

Build Coverage Version Dependencies Downloads License

rew is a collection of command-line tools for line-oriented text processing.

It includes tools for a wide range of tasks, such as:

  • Text filtering, transformation and generation.
  • File system paths manipulation.
  • Composition of parallel process pipelines.
  • Shell metaprogramming (code generation).

All tools are distributed as a single binary (similar to BusyBox).

Documentation

Visit rew website for installation, usage, examples and more.

Showcase

Let's start with output of the standard Unix find command:

$ find -type f

./README.TXT
./image_1.JPG
./image_2.JPEG

Use rew subcommands to query components of each path:

$ find -type f | rew base

README
image_1
image_2
$ find -type f | rew ext

TXT
JPG
JPEG

Combine multiple rew subcommands to get normalized results:

$ find -type f | rew ext | rew lower

txt
jpg
jpeg
$ find -type f | rew ext | rew lower | rew replace eg g

txt
jpg
jpg

Compose multiple pipelines using x subcommand:

$ find -type f | rew x 'out/{base}.{ext | lower | replace eg g}'

out/README.txt
out/image_1.jpg
out/image_2.jpg

Update the pattern to generate shell code:

$ find -type f | rew x 'mv {} out/{base}.{ext | lower | replace eg g}'

mv ./README.TXT out/README.txt
mv ./image_1.JPG out/image_1.jpg
mv ./image_2.JPEG out/image_2.jpg

And pipe it into a shell for execution:

$ find -type f | rew x 'mv {} out/{base}.{ext | lower | replace eg g}' | sh

Or into a tool like GNU parallel for even faster execution:

$ find -type f | rew x 'mv {} out/{base}.{ext | lower | replace eg g}' | parallel

You are not limited only to rew subcommands. Call whatever tool you like. For example, let's use sed instead of rew replace:

$ find -type f | rew x 'mv {} out/{base}.{ext | lower | sed s/eg/g/}' | sh

More examples can be found in rew x command reference or by calling rew x --examples.

Have fun using rew!

Development

The project uses just to run development tasks.

Run just without arguments to show available recipes.

License

rew source and documentation are released under the MIT License.