LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   checking if a file has a specified extension in csh (https://www.linuxquestions.org/questions/programming-9/checking-if-a-file-has-a-specified-extension-in-csh-551595/)

grinch 05-05-2007 06:36 PM

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

Dark_Helmet 05-05-2007 06:46 PM

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.

grinch 05-05-2007 07:34 PM

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

grinch


All times are GMT -5. The time now is 11:47 PM.