[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