ls with regular expression | Unix Linux Forums | UNIX for Dummies Questions & Answers

  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 Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 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 12-08-2009
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 23 November 2014, 6:47 PM EST
Location: Amsterdam
Posts: 9,611
Thanks: 293
Thanked 2,448 Times in 2,196 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 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 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
Regular expression in AWK jolecanard Shell Programming and Scripting 3 05-08-2009 08:48 AM
regular expression [^ ] iengca Shell Programming and Scripting 9 06-18-2008 10:45 AM
Regular expression maxvirrozeito UNIX for Dummies Questions & Answers 1 12-14-2007 08:02 AM
Need help in Regular Expression mahabunta UNIX for Dummies Questions & Answers 2 09-26-2006 06:11 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 11:59 AM



All times are GMT -4. The time now is 10:42 PM.