The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace *.sqc files with *.sqC extension rameshonline Shell Programming and Scripting 7 06-05-2009 04:07 AM
How to get files with a specific extension janavenki Shell Programming and Scripting 9 11-27-2007 08:56 PM
Feedback: Allow tar.gz extension for files DukeNuke2 Post Here to Contact Site Administrators and Moderators 2 08-29-2007 02:22 PM
finding duplicate files by size and finding pattern matching and its count jerome Sukumar Shell Programming and Scripting 2 12-01-2006 04:20 AM
How to list files will no extension Wing m. Cheng UNIX for Dummies Questions & Answers 5 02-22-2002 02:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-15-2008
amnesiaiom amnesiaiom is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
CSH - finding files with the same file extension

Hey,

I'm having a problem finding out if a directory holds any files with a certain file extension, for example .txt.

I have tried:
HTML Code:
if (! -e "*.txt")
and I've tried:
HTML Code:
set FILES=`ls *`

        echo "Found $FILES"

        foreach FILE ($FILES)
		
if($FILE == "*.txt")
And neither of these work... any ideas? Your help is much appreciated!!
  #2 (permalink)  
Old 04-15-2008
Dave Miller's Avatar
Dave Miller Dave Miller is offline
Registered User
  
 

Join Date: Dec 2007
Location: Northern NJ, USA
Posts: 151
Are you looking for the file names, or just want to know if there is at least one file with the .txt extension?

Maybe there's a better way, and mind you I'm using KSH, but here's what I'd do:

count=`ls /path/*.txt | grep -c txt`
  #3 (permalink)  
Old 04-15-2008
amnesiaiom amnesiaiom is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 2
I am trying to check if there is a txt file within a directory, and if ther is I need to do one thing, and if there isn't I need to do something else.

I have tried the code sample and it works I can now use the returning value within a variable and compare this in an if statement.

Thank you for your help!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0