files and Regular expressions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers files and Regular expressions
# 1  
Old 10-07-2010
files and Regular expressions

Legends,

Please help me out.
I have the following two files. And i want to list all of them using a regular expression. How do i do that?

abc000
abc000.gz

Now if i use ls -ltr abc000[.gz]
it doesn't work.

Please help.
# 2  
Old 10-07-2010
"ls" doesn't use regular expressions but filename generation/expansion.

If you are using ksh93 (ksh88 maybe), this would match both of these files and no other:

Code:
ls -ltr abc000*(.gz)

The same command will work with bash when this option is set first:
Code:
shopt -s extglob

With most other shells, the simpler
Code:
ls -ltr abc000*

will pick both of these files but potentially others too.
This User Gave Thanks to jlliagre For This Post:
# 3  
Old 10-07-2010
ls -ltr abc000*
# 4  
Old 10-07-2010
Thanks jlliagre,

But do we have another option to run in bash. because it is pre defined script and shopt -s extglob is not permitted and neither i can edit the script.
# 5  
Old 10-07-2010
If you can't edit the script, what are you asking for exactly ??
# 6  
Old 10-07-2010
There is a perl script already existing (say abc.perl) and the file name is passed as an argument.

/tmp/abc.pl /tmp/abc000*(.gz)

This is giving "unexpected token" error.

Now, how do i pass the argument in(bash) so that it taken the expression.?
# 7  
Old 10-07-2010
Code:
shopt -s extglob
/tmp/abc.pl /tmp/abc000*(.gz)

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions

I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav' I want to move the characters beginning with - end before. I have different files with random... (2 Replies)
Discussion started by: XP_2600
2 Replies

2. Shell Programming and Scripting

move files using regular expressions

Hi, I have bunch of files in my home directory which starts with "s" and I need to move them into a directory. How can I use regex to do that? some of file names are: sample-script say-now script1 (6 Replies)
Discussion started by: bashily
6 Replies

3. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

4. Shell Programming and Scripting

Regular expressions help

need a regex that matches when a number has a zero (0) at the end of it so like 10 20 120 30 330 1000 and so on (6 Replies)
Discussion started by: linuxkid
6 Replies

5. Shell Programming and Scripting

Regular Expressions

what elements does " /^/ " match? I did the test which indicates that it matches single lowercase character like 'a','b' etc. and '1','2' etc. But I really confused with that. Because, "/^abc/" matches strings like "abcedf" or "abcddddee". So, what does caret ^ really mean? Any response... (2 Replies)
Discussion started by: DavidHe
2 Replies

6. Shell Programming and Scripting

Regular Expressions

#!/usr/bin/perl $word = "one last challenge"; if ( $word =~ /^(\w+).*\s(\w+)$/ ) { print "$1"; print "\n"; print "$2"; } The output shows that "$1" is with result one and "$2" is with result challenge. I am confused about how this pattern match expression works step by step. I... (8 Replies)
Discussion started by: DavidHe
8 Replies

7. UNIX for Dummies Questions & Answers

Regular expressions

In regular expressions with grep(or egrep), ^ works if we want something in starting of line..but what if we write ^^^ or ^ for pattern matching??..Hope u all r familiar with regular expressions for pattern matching.. (1 Reply)
Discussion started by: aadi_uni
1 Replies

8. UNIX for Dummies Questions & Answers

regular expressions

how to find for a file whose name has all characters in uppercase after 'project'? I tried this: find . -name 'project**.pdf' ./projectABC.pdf ./projectABC123.pdf I want only ./projectABC.pdf What is the regular expression that correponds to "all characters are capital"? thanks (8 Replies)
Discussion started by: melanie_pfefer
8 Replies

9. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

10. Programming

regular expressions in c++

How do I use the regular expressions in c++? (2 Replies)
Discussion started by: szzz
2 Replies
Login or Register to Ask a Question