LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 05:35 AM   #1
circus78
Member
 
Registered: Dec 2011
Posts: 129

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, 05:59 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,841

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

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

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, 12:29 AM   #5
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,841

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
? 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, 12:53 PM   #6
circus78
Member
 
Registered: Dec 2011
Posts: 129

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, 02:55 AM   #7
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,841

Rep: Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287Reputation: 1287
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-06-2012 11:54 PM
[SOLVED] Regex question Steve W Programming 10 05-04-2011 01: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 01:10 AM
A question about regex trist007 Linux - Newbie 12 09-16-2010 01:20 PM
regex.h question MTK358 Programming 4 06-08-2010 04:10 PM


All times are GMT -5. The time now is 08:00 AM.

Main Menu
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