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?

link|improve this question

44% accept rate
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
feedback

3 Answers

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!

link|improve this answer
feedback

Perl!

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

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.