[ILUG] regular expression question
Padraig Brady
padraig at antefacto.com
Tue Nov 13 17:12:15 GMT 2001
Mark McLoughlin wrote:
> Hi Padraig,
>
> On Tue, 13 Nov 2001, Padraig Brady wrote:
>
>
>>[padraig at pixelbeat findul]$ cat input.txt
>>/lib/libthread_db-1.0.so
>>/usr/lib/gphoto/libgphoto_canon.so.0
>>/usr/lib/lib_alchemistmodule.so
>>
>>
>>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.
>>So try 1: Match 1 or more characters not /
>>
>>[padraig at pixelbeat findul]$ cat input.txt |
>>grep "\(^/usr/lib/[^/]+$\|^/lib/\)"
>>/lib/libthread_db-1.0.so
>>
>>This didn't match the last entry, why?
>>
>
> Strange indeed. Interestingly
>
> grep "\(^/usr/lib/[^/][^/]*$\|^/lib/\)" < input.txt
>
> works. So it may be a bug ?
Intersting indeed.
> Out of curiousity - how come you didn't try something like
>
> grep "^/\(usr/lib$\|^lib\)/[^/]+$" < input.txt
More correctly:
[padraig at pixelbeat findul]$ grep "^/\(usr/lib\|lib\)/[^/]*$" input.txt
/lib/libthread_db-1.0.so
/usr/lib/lib_alchemistmodule.so
[padraig at pixelbeat findul]$ grep -E "^/(usr/lib|lib)/[^/]+$" input.txt
/lib/libthread_db-1.0.so
/usr/lib/lib_alchemistmodule.so
Yes they are nicer, thanks.
> Good Luck,
> Mark.
cheers,
Padraig.
More information about the ILUG
mailing list