Operating System - HP-UX
1748156 Members
3739 Online
108758 Solutions
New Discussion юеВ

regex: exclude file from directory

 
Alexandre Arents
Occasional Advisor

regex: exclude file from directory


Hello,

I'm looking for a regex pattern which exclude a specific file/directory and match all others within an directory, example:

$ls -ld /rep/*
/rep/car
/rep/loft
/rep/andsoon
...
and I want to match all filename but not loft

The best I found is:
ls -ld /rep/[^l]*
which exclude all filename beginning by 'l' but not the string "^loft$".

Any idea ?
Thanks

4 REPLIES 4
Pete Randall
Outstanding Contributor

Re: regex: exclude file from directory

Does it have to be with regexp(s) or would grep do?
ls -ld /rep/* |grep -v loft


Pete

Pete
Alexandre Arents
Occasional Advisor

Re: regex: exclude file from directory


I forgot to tell you something:

This is for a veritas netbackup policy configuration which use regex library but not a pipe to grep.
Michael Schulte zur Sur
Honored Contributor

Re: regex: exclude file from directory

Hi,

^ means beginning of string
! means not.

try this:
ls -ld /rep/* | grep -v /rep/loft


greetings,

Michael
Michael Schulte zur Sur
Honored Contributor

Re: regex: exclude file from directory

Hi,

btw, regular expressions and the way a shell evaluates file names are different. We need to know for sure, what veritas uses.

greetings,

Michael