Go Back   The UNIX and Linux Forums > Special Forums > UNIX Desktop for Dummies Questions & Answers


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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-22-2012
Registered User
 
Join Date: Jul 2012
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
Registered User
 
Join Date: Jul 2012
Location: San Jose, CA
Posts: 1,481
Thanks: 62
Thanked 534 Times in 467 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
Registered User
 
Join Date: Oct 2009
Location: spaceBAR Central
Posts: 304
Thanks: 0
Thanked 59 Times in 59 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
Registered User
 
Join Date: Jul 2012
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 08:22 AM.