LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-04-2011, 10:47 AM   #1
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Rep: Reputation: 38
What's Wrong with the RegEx [Simple]


Ok, I'm just started to feel stupid because I just can't seem to get regular expressions working in Linux the way they work on Windows.

To keep things simple, here is a ridiculously elementary expression that should return a list of mounted samba shares.

Match the lines that start with '//'
Match any character until reaching whitespace

Code:
$ egrep '^//[^ ]*' /etc/mtab
I have tried multiple variations ([^\s],\S, etc) to match until whitespace is reached but no matter which variation I try the expression always matches the entire line and not just the share.

Code:
//baileyfs01/Profiles/developer /home/developer/network/baileyfs01/Profiles/developer cifs rw,mand 0 0
I've started to rely too much on $ cut -d ' ' in a lot of the scripts I'm migrating over to Linux and I want to get this RegEx figured out so I can do things properly before I get too wrapped up in recoding the more advanced programs and scripts.
 
Old 04-04-2011, 10:54 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,625

Rep: Reputation: 518Reputation: 518Reputation: 518Reputation: 518Reputation: 518Reputation: 518
grep returns the whole line by default. sounds like you want egrep's -o option.

Code:
       -o, --only-matching
              Print only the matched (non-empty) parts of a matching line, with each such part on
              a separate output line.
 
1 members found this post helpful.
Old 04-04-2011, 11:04 AM   #3
thund3rstruck
Member
 
Registered: Nov 2005
Location: East Coast, USA
Distribution: Fedora 18, Slackware64 13.37, Windows 7/8
Posts: 346

Original Poster
Rep: Reputation: 38
Thanks AlucardZero (that nic wouldn't happen to be based on CastleVania's Alucard?)

DOH! I just learned something new...

Cheers!
 
  


Reply

Tags
egrep, regex, regular expressions


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
[SOLVED] fail2ban does not ban, maybe my regex is wrong? JeanC Linux - Server 2 03-17-2011 10:01 AM
Could anyone show me a simple example of regex or pcre program on linux C? bellhuang Linux - Software 3 02-07-2010 06:05 AM
[SOLVED] Simple regex match without replace? nrg Programming 1 11-21-2009 03:04 AM
simple regex not so simple (perl) ludeKing Programming 5 03-02-2005 02:29 AM
simple perl and regex phlx Programming 6 12-03-2004 03:01 PM


All times are GMT -5. The time now is 09:05 PM.

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