Unix/Linux Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

ls with regular expression

UNIX for Dummies Questions & Answers


Tags
ls

Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-08-2009
rkgudde rkgudde is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 9 August 2013, 1:48 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ls with regular expression

I currently list and sort all the files in a directory which begin with an Upper Case C and end with the extension '#finished#'.

Here is the command I use:

ls -tr $currentDir/[C]*.#finished#

what i need to do now is list all the files in a directory that begin with upper case C and end with either '#finished#' or 'finsihed'.

can i do this with one `ls` statement?

my simple mind tries this:

filelist=`ls -tr $currentDir/[C]*.#finished#`
filelist=$filelist+`ls -tr $currentDir/[C]*.finished`

however I need to keep the sort order in tact for all files regardless of thier extension.

thanks
Sponsored Links
    #2  
Old Unix and Linux 12-08-2009
rugdog rugdog is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 13 January 2011, 8:10 AM EST
Posts: 19
Thanks: 0
Thanked 3 Times in 3 Posts
just put the two expressions in the same line of the ls, like this:

filelist=`ls -tr $currentDir/[C]*.#finished# $currentDir/[C]*.finished`
Sponsored Links
    #3  
Old Unix and Linux 12-08-2009
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 3 May 2015, 11:49 PM EDT
Location: Amsterdam
Posts: 10,153
Thanks: 329
Thanked 2,675 Times in 2,392 Posts
It is called globbing not a regluar expression. You can use extended globbing to do what you want if your shell supports it.

Code:
ls -tr $currentDir/C*.?(#)finished?(#)

But probably you can afford to be a little bit less precise and just use:

Code:
ls -tr $currentDir/C*.*finished*

    #4  
Old Unix and Linux 12-08-2009
rkgudde rkgudde is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 9 August 2013, 1:48 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Bug

thank you both. the first solution worked perfectly.
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular expression in AWK jolecanard Shell Programming and Scripting 3 05-08-2009 07:48 AM
regular expression [^ ] iengca Shell Programming and Scripting 9 06-18-2008 09:45 AM
Regular expression maxvirrozeito UNIX for Dummies Questions & Answers 1 12-14-2007 07:02 AM
Need help in Regular Expression mahabunta UNIX for Dummies Questions & Answers 2 09-26-2006 05:11 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 10:59 AM



All times are GMT -4. The time now is 01:00 AM.