LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-25-2013, 06:35 AM   #1
circus78
Member
 
Registered: Dec 2011
Posts: 155

Rep: Reputation: Disabled
Question about regex


Hi,

how can I match /home, /home2, /home3 (and so on) with regular expression?

This:

Code:
find /home[0-9]/*
only matches /home2, /home3 but not /home

Thank you very much.
 
Old 11-25-2013, 06:59 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
probably: find /home[0-9]/* /home/* ....
 
1 members found this post helpful.
Old 11-25-2013, 07:16 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Code:
find /home{,{0..9}}
 
Old 11-26-2013, 04:22 PM   #4
circus78
Member
 
Registered: Dec 2011
Posts: 155

Original Poster
Rep: Reputation: Disabled
Hi,
just another doubt.
With bash it's correct to use home* in order to match: home, home2, home3, and so on..

Quote:
# mkdir home
# mkdir home2
# mkdir home3
# mkdir home4
# ls home*
home:
./ ../

home2:
./ ../

home3:
./ ../

home4:
./ ../
while with "find" it's necessary to use a different command.. so it's a bit confusing: when it's correct to use shell globbing and when to use regexp?
 
Old 11-27-2013, 01:29 AM   #5
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
? that is implied: shell globbing can be used in shells and regexp can be used with tools which can interpret those expressions...
 
Old 11-28-2013, 01:53 PM   #6
circus78
Member
 
Registered: Dec 2011
Posts: 155

Original Poster
Rep: Reputation: Disabled
Hi pan64,

ok, so the first two answers are using shell globbing instead of regexp, right?

Quote:
find /home[0-9]/*
Quote:
find /home{,{0..9}}
Thankyou
 
Old 11-29-2013, 03:55 AM   #7
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
yes, just one comment: find can handle regexp, see man page and the -regex switch (that is not exactly what you need now)
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regex question dnoy Linux - General 2 12-07-2012 12:54 AM
[SOLVED] Regex question Steve W Programming 10 05-04-2011 02:43 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 02:10 AM
A question about regex trist007 Linux - Newbie 12 09-16-2010 02:20 PM
regex.h question MTK358 Programming 4 06-08-2010 05:10 PM


All times are GMT -5. The time now is 11:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration