LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-05-2007, 06:36 PM   #1
grinch
LQ Newbie
 
Registered: Jul 2006
Distribution: Slackware 11
Posts: 12

Rep: Reputation: 0
checking if a file has a specified extension in csh


Hi guys,
How can i check if a file x has *.html extension using csh. I understand that csh is not the way
to go, but i need to do it using csh.

The code i have is this:
Basically, given a directory the script iterates through the files in that directory and the files of its subdirectories. If a file has html extension, it will do something with that file.

Code:
...
cd $dir
foreach filename(*)
   if (-d $filename) then
      $0 $filename
   else
      if ("the filename has html extension") <---- i don't know how to do it
         # do something with the file
      endif
   endif
end

...
I know that csh is no good but i don't need solutions in bash or perl.
Thanks
grinch
 
Old 05-05-2007, 06:46 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
First of all, let me say "I understand". Specifically, the need to head off suggestions before they come. There will be the inevitable "you should use bash" and "perl could do it easy" and other similar comments. I hate that, and I try to put in as much "encouragement" in my questions to stop them from coming if they aren't acceptable solutions.

I won't mention any of those types of responses

There is another thread a few days back that touched on this. Here's the link. The post is about a bash script, but a reply further down gives a solution using sed. That's why I'm linking to it.

The thread also brings up another point you did not elaborate on: what do you consider to be an extension? any and all text following the first period, any and all text following the last period, or something else? The sed command will change depending on your definition.

Last edited by Dark_Helmet; 05-05-2007 at 07:35 PM.
 
Old 05-05-2007, 07:34 PM   #3
grinch
LQ Newbie
 
Registered: Jul 2006
Distribution: Slackware 11
Posts: 12

Original Poster
Rep: Reputation: 0
cheers

Thanks for directing me to that post i found all the information i needed there.

grinch
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux file extension vs Dos file Extension? manaa Linux - Newbie 6 02-12-2009 04:19 PM
Checking for XComposite extension failed with Beryl davidguygc Linux - Desktop 10 05-08-2007 02:13 AM
convert .bat / .csh file to .sh files massoo Programming 1 03-06-2006 06:10 PM
why when redirecting output to a file any file extension seems to be fine? dr_zayus69 Linux - General 1 05-21-2005 04:09 AM
Checking file extension in TCL? liguorir Programming 2 06-14-2004 06:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration