Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .