LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] regular expression question

[ILUG] regular expression question

Padraig Brady padraig at antefacto.com
Tue Nov 13 17:16:45 GMT 2001


Dave Neary wrote:

> Padraig Brady wrote:
> 
>>OK I want to only show files in /lib/ or /usr/lib/
>>so I'm trying to exclude lines that have a / after
>>these 2 strings.
>>
> 
> egrep '^\/lib\/[^\/]+$|^\/usr\/lib\/[^\/]+$'
> and 
> grep '^\/lib\/[^\/]\{1,\}$\|^\/usr\/lib\/[^\/]\{1,\}$'
> both work for me. The only immediate difference I see between our
> efforts is that you didn't escape the slashes. And + doesn't have the
> same meaning in basic regular expressions as it does in extended
> regexps. In old regexps, a + is a +. In old regexps, to get the same
> thing you have to use \{1,\}


Cheers, Dave that's it.
I really wish there was only 1 regexp syntax to learn.

 From the man page:

"In basic regular expressions the metacharacters ?, +, {, |, (, and )
lose their special meaning; instead use the backslashed versions \?, \+,
\{, \|, \(, and \)."

So I need to do \+ not just + so....

[padraig at pixelbeat findul]$ grep "^/\(usr/lib\|lib\)/[^/]\+$" input.txt
/lib/libthread_db-1.0.so
/usr/lib/lib_alchemistmodule.so

cheers,
Padraig.





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell