Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-29-2012, 10:29 PM   #1
Registered: Jan 2012
Posts: 32

Rep: Reputation: Disabled
Regular Expressions - grouping

Hello, I am a University biology student. I am trying to figure out regular expressions, but I am getting both confused and frustrated trying to group one or more test for use with grep. I was hoping someone here might be able to help.

Given the file:
with contents: "

I would like to use grep to find the value a such that the command is similar to:

grep '[\,]+' a_file
$ grep '[\,]+' a_file
$ grep '\,+' a_file
$ grep '(\,)+' a_file
$ grep '(,)+' a_file
$ grep '{\,}+' a_file
I realize I could just use the comma, but once I need a more complicated expression that would break down.

Old 01-29-2012, 10:44 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
For efficiency reasons, plain grep only handles the basic set of regular expression operators. Try using egrep or grep -E if you wish to make use of the extended set of operators (I should note that the GNU grep can use the '+' operator, but you have to escape it, eg grep ',\+', just to confuse things)

In general the term 'regular expression' is only loosely defined, and different tools do not always have exactly the same operator set.

Last edited by neonsignal; 01-29-2012 at 10:55 PM.
1 members found this post helpful.
Old 01-31-2012, 10:03 AM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
BTW, is the backslash intended to escape the comma above?

Not only does the comma not have any special regex meaning that needs escaping, but even if it did, only a few characters retain any special meaning when inside a bracket expression. And those are generally handled by careful positioning inside the brackets so that they can't be interpreted as special (the "]" must be the first character in the list, "^" can't be the first, and "-" must be first or last).

Unless your regex is actually meant to match a string of either/both commas and backslashes, in which case it's perfect.

Check out the grep man page and info page for more on how it, and the regexes it supports, operates.
1 members found this post helpful.
Old 01-31-2012, 11:56 AM   #4
Registered: Jan 2012
Posts: 32

Original Poster
Rep: Reputation: Disabled
Thanks 'neonsignal' and 'David the H.'! That was helpful for getting started.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expressions ziggy25 Linux - Newbie 7 11-05-2007 07:57 AM
regular expressions. stomach Linux - Software 1 02-10-2006 07:41 AM
Regular Expressions markjuggles Programming 2 05-05-2005 12:39 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 11-01-2003 12:09 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:31 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration