Take the 2-minute tour ×

I'd like to print only few groups from text matching a regex. How can I do that in the Linux command line?

What other tools for text processing are there in Linux?

share|improve this question
if you just want to print some portions of text that match a regex, use grep -o –  glenn jackman Sep 23 '11 at 12:01

3 Answers 3

up vote 3 down vote accepted

Two programs I use frequently for this purpose are sed and awk.

grep has additional flavours, such as egrep and fgrep which alter how the given pattern is used.

The Unix Toolbox has a few examples on sed, awk and links to more resources!

share|improve this answer


perl -nE '/foo (\w+) bar/ and say "group 1 is $1";'
share|improve this answer

One way you might do it is through lang consoles, such as Ruby or Node.js. Both have access to filesystem and a host of things you can do with it. As I come from the front-end web world, I personally find Node.js's syntax to be easy to use.

share|improve this answer

Your Answer


