- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sh pattern matching problems
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 05:50 AM
04-09-2002 05:50 AM
Here are my files :
la1111.081.Z
la11_22.081.Z
la2222.025
labcd
I want to match files like these :
# ls la+([0-9]).081*
But I don't manage to use this pattern matching
inside a 'find' command.
# find . -name "la+([0-9]).081*"
doesn't work.
Instead,
# find . -name "la[0-9]*"
works, but this is not what i want.
Could somebody help me ?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 06:08 AM
04-09-2002 06:08 AM
Re: sh pattern matching problems
try
find la+([0-9]).081*
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 06:18 AM
04-09-2002 06:18 AM
Re: sh pattern matching problems
find . -name "la*[0-9].081*"
I am not a cracker in regular expresion, but you can read man 5 regexp ( 13 pages of .,+^[ and many others special chars.. ). Sure you will find the reason.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 06:45 AM
04-09-2002 06:45 AM
Re: sh pattern matching problems
Try this:
# find . -name "la*[0-9]*081*"
Check the man pages of find and regexp.
HTH,
Shiju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 08:21 AM
04-09-2002 08:21 AM
Re: sh pattern matching problems
Carlos and Shizu, your pattern matches too many files (the two listed first in my example, and i want only the first one).
I've read man pages. The problem is not "what would be the pattern to match my file ?" because I see it working with the 'ls' command.
But "How to use it with the 'find' command ?"
thanks anyway
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 08:31 AM
04-09-2002 08:31 AM
Re: sh pattern matching problems
Try this:
# find . -name la+([0-9]).081* -depth
This will check the subdirectories too.
HTH,
Shiju
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 08:53 AM
04-09-2002 08:53 AM
Re: sh pattern matching problems
ls | grep "^la\([0-9].*\)\.081.*"
so if you have these files:
# ls la*
la1111.081.Z la2222.025 labcd laninfo laninfo2.sh
la11_22.081.Z la22F22.025 lancards laninfo.sh
the grep returns this:
# ls | grep "^la\([0-9].*\)\.081.*"
la1111.081.Z
la11_22.081.Z
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 08:54 AM
04-09-2002 08:54 AM
Re: sh pattern matching problems
Try your find command without the quotes it works for me ...
find . -name la+([0-9]).081*
-Thanks,
Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 09:14 AM
04-09-2002 09:14 AM
Re: sh pattern matching problems
sorry, I misread your post, you only want this pattern:
la####.081*
so try this:
# ls | grep "^la\([0-9]\)\{4\}\.081.*"
la1111.081.Z
#
if you want this: la###...###.081*
then change the \{4\} to \{4,\} to say at least four digits but any more is ok also.
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 10:32 AM
04-09-2002 10:32 AM
Re: sh pattern matching problems
But I don't know why the 'find' command doesn't work.
Shabu, I do need quotes, and your command doesn't work when there are more than one file
matching. (explanation in my last post, about substitution)
It looks like the find command doesn't accept "(" symbols, only "?", "*" and "[".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 11:33 AM
04-09-2002 11:33 AM
Re: sh pattern matching problems
I think this will solve your purpose ...
find . -name "la[0-9]*.081*"
Thanks,
Shabu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 12:16 PM
04-09-2002 12:16 PM
Re: sh pattern matching problems
So it matches la4zzz.081
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 11:26 PM
04-09-2002 11:26 PM
Re: sh pattern matching problems
I didn't find a way to use quantifier that works in the name option of the find command, but if you need it in a script try something like this:
The files are :
la1111.081.Z
la11_22.081.Z
la123.081.Z
la2222.025
la23.081.Z
la23x.081.Z
labcd
The command (in one line):
# find . \( -name "la[0-9][0-9].*.Z" -o
-name "la[0-9][0-9][0-9][0-9].*.Z" -o
-name "la[0-9][0-9][0-9].*.Z" \)
./la1111.081.Z
./la123.081.Z
./la23.081.Z
Hope This helps
Lothar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2002 12:48 AM
04-10-2002 12:48 AM
Solution1- ls la+([0-9]).081* # runs OK
2- find la+([0-9]).081* # runs OK because REGEXP is interpreted by sh
3- find . -name "la+([0-9]).081*" # never runs. Even man find says that expression will be interpreted by regexp, in facts it do not work, and so it must be a issue of find. IMMO.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2002 01:21 AM
04-10-2002 01:21 AM
Re: sh pattern matching problems
Carlos, it could be the conclusion to the story !
I found an equivalent way to correspond to
#ls la+([0-9]).081*
find . -name "la*.081*" ! -name "la*[!0-9]*.081*"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2002 05:06 AM
04-10-2002 05:06 AM
Re: sh pattern matching problems
I've been trying to figure this out and can't. Hopefully someone else will.
I do know that you are correct to escape your regexp in the find command with quotes. Otherwise the shell will expand the regexp before passing it to find. The only files found would be ones with names that match those found in the current directory.
I'm still hoping for a resolution.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2002 05:36 AM
04-10-2002 05:36 AM
Re: sh pattern matching problems
You might like to try the GNU version of find at:
http://hpux.connect.org.uk/hppd/hpux/Gnu/findutils-4.1.5/
Or alternatively pipe the output through grep -E.
Regards,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2002 05:41 AM
04-10-2002 05:41 AM
Re: sh pattern matching problems
la111.081.Z la11_22.081.Z la2222.025 labcd
l1:/tmp 113 > perl -MFile::Find -le 'find(sub{m/^la\d+\.081/||return;print$File::Find::name},".")'
./la111.081.Z
l1:/tmp 114 >
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2002 05:58 AM
04-10-2002 05:58 AM