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


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

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-13-2012
Registered User
 
Join Date: Sep 2009
Location: Saskatchewan, Canada
Posts: 179
Thanks: 73
Thanked 2 Times in 2 Posts
regex for ls command

Forgive me if this has been posted, but I could not find them.
I have thousands of files from a permutation as:

Code:
intersect-1234.tab
intersect-9914.tab
intersect-0123456.tab
intersect-9134512.tab
......

Basically there are two groups, one is the
Code:
 intersect-[0-9][0-9][0-9][0-9].tab

and the other is
Code:
intersect-[0-9][0-9][0-9][0-9][0-9][0-9].tab

When I tried command:

Code:
ls intersect-[0-9]\{4\}.tab

or

Code:
ls intersect-[0-9]\{6\}.tab

neither worked but with error message:

Code:
ls: cannot access intersect-[0-9]{6}.tab: No such file or directory

It seems my regex is fine as when I used pipeline:

Code:
 ls *.tab | grep intersect-[0-9]\{6\}.tab

I must have missed something with the regex for ls? Anyone please give me clue?
Thanks for help!
Sponsored Links
    #2  
Old 07-13-2012
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 3,289
Thanks: 27
Thanked 450 Times in 351 Posts
Quote:
Originally Posted by yifangt View Post
I must have missed something with the regex for ls?
You have missed something indeed: shell regexps (aka "globs") and regexps are NOT the same.

See the man page of your shell for a detailed list of file globs, but if they aren't sufficient for your purpose you will have to do like you dike already: "ls | grep <some_regexp>" or something similar (awk, sed, ... all use the same regexps).

I hope this helps.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
yifangt (07-13-2012)
Sponsored Links
Closed Thread

Tags
ls, regex, repetitive occurence, shell commands

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
command to check existence of file name which has regex skpvalvekar Shell Programming and Scripting 2 06-24-2011 06:59 AM
Using regex in find command Zucriy Amsuna UNIX for Dummies Questions & Answers 27 04-22-2011 10:29 PM
Regex in find command siba.s.nayak UNIX for Dummies Questions & Answers 3 11-23-2010 01:33 PM
combining perl regex'es into a single command hcclnoodles Shell Programming and Scripting 4 09-23-2009 10:43 AM
testing for regex at command line ankimo UNIX for Dummies Questions & Answers 4 10-08-2008 02:18 PM



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