regex for ls command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers regex for ls command
# 1  
Old 07-13-2012
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!
# 2  
Old 07-13-2012
Quote:
Originally Posted by yifangt
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
This User Gave Thanks to bakunin For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

2. UNIX for Dummies Questions & Answers

Find command and regex

Hi All, We have to copy some files from a source directory to a destination directory. We only have to copy the file if the filename is in a list of values. We can use find command: find . -type f -name '*_111.txt' -o -name '*_115.txt' ... -exec cp {} /tmp \; But the list contains... (3 Replies)
Discussion started by: bartleby
3 Replies

3. Shell Programming and Scripting

Need Help with a sed command involving Regex

Hi, Iam a newbie to SED. I'm faced with a problem as described. Given the file with text 1 rwerwerwe rere 2 fdfefefe fsdfds 3 rerere ffff trtrt 4 aaaa 1234 asadsdsd 5 hfjfjfjsjfsf... (14 Replies)
Discussion started by: SShinde
14 Replies

4. Shell Programming and Scripting

REGEX for a Full_PATH/Command --with-options

Hello All, I'm trying to match some user input. The User input will be a FULL Path, a Command/Script Name, and any options they choose... I was able to get this to Match somewhat but I want to be able to print an Error if, for example, the user enters a trailing "/" after the Command_name... (9 Replies)
Discussion started by: mrm5102
9 Replies

5. Shell Programming and Scripting

command to check existence of file name which has regex

Hi All. Pls help me with the command to check existence of files (I'll mention name of the file as regex) and proceed with my further processing if atleast one of them exists in detail, I've a dir /tmp/TURP, which may or may not have files named with "exter*.txt" I need to check and... (2 Replies)
Discussion started by: skpvalvekar
2 Replies

6. UNIX for Dummies Questions & Answers

Using regex in find command

I don't understand why the following simple command is not working: find assign{1,2}Variations don't work, either: find assign+ find assign? ls assignAll I am trying to do is make an alias for running a C++ program of the name assign# or assign##. But the regular expressions aren't working. @_@... (27 Replies)
Discussion started by: Zucriy Amsuna
27 Replies

7. UNIX for Dummies Questions & Answers

Regex in find command

Hi, I need to find out the files whcih contains date in YYYYMMDD in their name. I don't know if I can use regex in side find. Now I am using commad for the same purpose which is not full proof. find . -name "**" -print But I want then It should contain at lease 8 digit in their... (3 Replies)
Discussion started by: siba.s.nayak
3 Replies

8. Shell Programming and Scripting

Using SED command in a shell script: Unterminated address regex

Hi All, I am trying to use a sed command in a shell script in order to delete some lines in a file and I got the following error message. I don't understand why it is not working 'cause I have tried with simple quotes, then with double-quotes, and it is not working. sed: -e expression #1,... (7 Replies)
Discussion started by: Alpha3363
7 Replies

9. Shell Programming and Scripting

combining perl regex'es into a single command

Hi Gurus, I have a working solution for munging my data but just wondered if there was a way I could streamline it into a single command at all ? my $filesystem = "backup/server56/oracle/" $filesystem =~ s/\/+$// ; # remove the trailing slash(es) from the path specified... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

10. UNIX for Dummies Questions & Answers

testing for regex at command line

hi unixers, i wonder if someone can tell me how i can check for a regex at the command line? if any parameter begins with a special character then do this else do thatthanks for your help. (4 Replies)
Discussion started by: ankimo
4 Replies
Login or Register to Ask a Question