Searching for files with specific extensions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching for files with specific extensions
# 1  
Old 05-20-2011
Searching for files with specific extensions

Hi,

Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log.

I've tried to use ls *.txt *.log which works if there are both file-types, however raises an error if only one file-type is there.

Many thanks for any help,

Neil
# 2  
Old 05-20-2011
Code:
ls *.log *.txt 2>/dev/null

# 3  
Old 05-20-2011
Thanks Danmero - unfortunately, this doesn't give what I need. I'm doing further processing at this point, and suppressing errors stops other elements working.

Incidentally, I was thinking a regular expression could be used, as it's simple to do this in grep, however I'm not sure how this could be done using ls?

Thanks,

Neil
# 4  
Old 05-20-2011
Code:
 ls | grep -E '(.*\.log$|.*\.txt$)'

This User Gave Thanks to verdepollo For This Post:
# 5  
Old 05-23-2011
That works perfectly. Thanks very much, verdepollo.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Searching the value of a specific attribute among xmls files from a particular directory location

Hi Folks , I have the different xml files at the following directory `/opt/app/rty/servers/tr/current/ops/config` Let's say there are three files named abc.xml bv.xml ert.xml Now inside these xml there can be many tags as like shown below <bean id="sdrt"... (6 Replies)
Discussion started by: unclesamm
6 Replies

2. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

3. Shell Programming and Scripting

Searching for a specific string in a file

Hi I am trying to search for a certain set of patterns within a file, and then perform other commands based on output. testfile contents: password requisite pam_cracklib.so lcredit=-1 ucredit=-1 ocredit=-1 script: D="dcredit=-1" if then echo $D exists else echo $D doesnt... (8 Replies)
Discussion started by: bludhemn
8 Replies

4. UNIX for Advanced & Expert Users

Watch directory and move specific file extensions

Hi all, This is actually more for my lazyness then anything else, but I think others might find it useful to use as well. Basically this is what I am trying to achieve... In my ubuntu home dir under Downloads is where firefox saves everything by default, now I know that you can manually... (3 Replies)
Discussion started by: STOIE
3 Replies

5. UNIX for Dummies Questions & Answers

Searching for specific filenames

Hi I would like to know how to search through a directory and pull out files that has a specific pattern in the filename. For example if the filename has "bsc" in it, then that file must be moved to another directory where I will perform some operations on it. I know grep can be used, but I'm... (17 Replies)
Discussion started by: ladyAnne
17 Replies

6. UNIX for Advanced & Expert Users

How to perform Grep on many Gzip files, Searching for Specific information

Hello, I am wondering if you can assist with my question and ask kindly for this. I have a number of files that are listed as file1.gz through file100.gz. I am trying to perform a grep on the files and find a specific date that only resides within within one of the files. There are... (3 Replies)
Discussion started by: legharb
3 Replies

7. Shell Programming and Scripting

grep - searching for a specific string

ppl, this is my "file" with fields orderno orderdate orderdesc telno street city 1 01/04/2006 abc 123 100 tampa 2 01/04/2006 abc 123 100 tampa 3 01/04/2006 abc 123 100 tampa 4 01/04/2006 abc ... (2 Replies)
Discussion started by: manthasirisha
2 Replies

8. UNIX for Dummies Questions & Answers

searching text files on specific columns for duplicates

Is it possible to search through a large file full of rows and columns of text and retrieve only the rows that contain duplicates fields, searchiing for duplicates on col4 & col6 Sample below Col1 col2 col3 col4 col5 col6 G405H SURG FERGUSON ... (2 Replies)
Discussion started by: Gerry405
2 Replies

9. Shell Programming and Scripting

Searching for a specific string in an argumnet

I want to check the second argument for a specific string . The code below is what I am trying, but I get: UX:test (./test): ERROR: { if ($0 ~ /StringImLooking4/) {print $1} }: Unknown operator I want to test if the second argument contains the string StringImLooking4 Unixware 7 ... (1 Reply)
Discussion started by: dinplant
1 Replies
Login or Register to Ask a Question