Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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!

share|improve this answer
add comment

Perl!

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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