[SOLVED] find command match pattern | Unix Linux Forums | UNIX Desktop for Dummies Questions & Answers

  Go Back    


UNIX Desktop for Dummies Questions & Answers Discuss UNIX and Linux user interfaces like GNOME, KDE, CDE, and Open Office here. All UNIX and Linux Newbies Welcome !!

[SOLVED] find command match pattern

UNIX Desktop for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-22-2012
satin1321 satin1321 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 22 October 2012, 2:56 AM EDT
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
[SOLVED] find command match pattern

Hello,

I would like to ask you, how to match directory names. I need to find only directories, which are created only from numbers and doesn't include any letters.

I used command


Code:

find $AC_WORKDIR/work_archive/test/$dirs_years -maxdepth 1 -name \[0-9]\* -print

If I have dirs like
12
12ab
ab12

it gives dirs 12, 12ab. I need only dir 12. Thank you for your answer
Sponsored Links
    #2  
Old 09-22-2012
Don Cragun's Avatar
Don Cragun Don Cragun is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 24 April 2014, 7:07 PM EDT
Location: San Jose, CA, USA
Posts: 3,497
Thanks: 141
Thanked 1,211 Times in 1,025 Posts
The awk script below will print all directory names in or under $AC_WORKDIR/work_archive/test/$dirs_years with names that only contain digits. You can put back in the maxdepth clause if you only want directories in (not under) that directory. (Note, however, that -maxdepth is not required by the standards and is not present in all implementations of the find utility.)

Code:
find $AC_WORKDIR/work_archive/test/$dirs_years -type d ! -name '*[!0-9]*'


Last edited by Don Cragun; 09-22-2012 at 07:16 PM.. Reason: Add note about maxdepth
Sponsored Links
    #3  
Old 09-22-2012
spacebar's Avatar
spacebar spacebar is offline
Registered User
 
Join Date: Oct 2009
Last Activity: 15 April 2014, 9:00 PM EDT
Location: spaceBAR Central
Posts: 434
Thanks: 0
Thanked 68 Times in 68 Posts
Try the below example:

Code:
$ cd tmp
$ ls -l
drwxr-xr-x+ 1 Sep 22 17:33 1
drwxr-xr-x+ 1 Sep 22 17:34 12
drwxr-xr-x+ 1 Sep 22 17:34 12ab
drwxr-xr-x+ 1 Sep 22 17:34 2
drwxr-xr-x+ 1 Sep 22 17:34 ab12
drwxr-xr-x+ 1 Aug 22 19:14 txt2regex-0.8

$ find . -maxdepth 1 -regex "./[0-9]*"
./1
./12
./2

    #4  
Old 09-25-2012
satin1321 satin1321 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 22 October 2012, 2:56 AM EDT
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
Thank you for your help
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Solved] weird in find -exec command lsy UNIX for Dummies Questions & Answers 12 09-03-2012 08:09 AM
[Solved] Find duplicate and add pattern in sed/awk lolworlds Shell Programming and Scripting 0 02-03-2012 06:54 AM
[Solved] Assistance with find command please Condmach UNIX for Dummies Questions & Answers 2 10-25-2011 07:40 AM
fetch last line no form file which is match with specific pattern by grep command Himanshu_soni Shell Programming and Scripting 13 02-01-2011 06:37 AM
find: No match due to find command being argument mst3k4l Shell Programming and Scripting 2 08-10-2009 09:48 AM



All times are GMT -4. The time now is 07:40 PM.