CSH - finding files with the same file extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting CSH - finding files with the same file extension
# 1  
Old 04-15-2008
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  
Old 04-15-2008
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  
Old 04-15-2008
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!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete all files of a particular name & extension except one file.

I wish to delete all files that starts with "body<any number of digits>.xml" except body65.xml on Linux 7 bash shell So, from the below files body64.xml body.sh body65.xml body655.xml body565.xml body66.xml hello65.xml My command should delete all files except the below. body.sh... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

3. Shell Programming and Scripting

Finding file extension on C Shell script

I very new to C Shell. I am trying to do is read from Command line. Find the if the file is zip, .txt, symbloic link,pipe, unknow (if file is not zip, txt, sy....) here is what I what got so far. I am very stuck atm Please help me out : If the file is symblooc link what file is link to ... (12 Replies)
Discussion started by: madbull41
12 Replies

4. Shell Programming and Scripting

Split a file into multiple files with an extension

Hi I have a file with 100 million rows. I want to split them into 1000 subfiles and name them from 1.xls to 1000.xls.. Can I do it in awk? Thanks, (8 Replies)
Discussion started by: Diya123
8 Replies

5. Shell Programming and Scripting

Changing file extension in csh alias

I want to type only the filename of a gcc source that has ".syn" as an extension and copy it, changing the extension to ".c" so it can be compiled. I do it as follows: if (-e $1.syn) then /bin/cp $1.syn $1.c endif This works fine, but if I want to repeat the compilation by... (1 Reply)
Discussion started by: ygmwayne
1 Replies

6. Shell Programming and Scripting

Finding tags in file names using csh

I have the following script and want to check if in each $f there exists either a "drw" or "smp" tag in the file name. How can I do it? For example npt06-32x24drw has the "drw" tag npt06-32x24smp has the "smp" tag npt06-32x24 no "drw" or "smp" tag found #!/bin/csh set iarg = 0... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

Adding lines to files based on file extension

I have posted this before but did not get many replies, so here it goes again. I have several files name like this If the file extension is 1a, I woould like to add at the beggining of the file the following sequence If the file extension is 1b, thn the entry that should be added is the next... (2 Replies)
Discussion started by: Xterra
2 Replies

8. Shell Programming and Scripting

Extracting file name and finding extension of the file

Hi., How to extract the extension of a file which are present in the directory?. In my script I tried something like: echo abc_ss_222_54.txt | awk -F"" '{print $5}' But I din't got .txt echoed in console. Pl. suggest a solution for this. And also, for finding a specific... (1 Reply)
Discussion started by: IND123
1 Replies

9. Shell Programming and Scripting

Csh script get file extension

Hi All I have a csh shell script which should check if a given file is a zip file as below: **************************************** #!/bin/csh -f if ]; then echo is a zip file else echo sorry not a zip file endif exit **************************************** ... (1 Reply)
Discussion started by: raj144
1 Replies

10. UNIX for Dummies Questions & Answers

Removing prefix from multiple files and renaming file extension

Hello i have the files in this format pdb1i0t.ent pdb1lv7.ent pdb1pp6.ent pdb1tj2.ent pdb1xg2.ent pdb2b4b.ent pdb2ewe.ent Now i have to remove the prefix pdb from all the files and also i need to change the extension of .ent to .txt The new file should look like this ... (3 Replies)
Discussion started by: empyrean
3 Replies
Login or Register to Ask a Question