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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to get file extension shirleyeow Shell Programming and Scripting 17 01-17-2008 05:40 AM
remove file extension prvnrk Shell Programming and Scripting 12 08-05-2007 03:46 AM
filename extension check - regular expression devs Shell Programming and Scripting 4 03-02-2007 12:01 PM
Check file extension mahalakshmi Shell Programming and Scripting 6 12-27-2006 10:15 AM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 11:46 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-27-2007
Registered User
 

Join Date: Nov 2007
Posts: 2
How do i check whether a file has extension?

Hi,

How do i check whether a file has extension?

I need to code a script that will check whether a file has extension or not. Say a file Rpt200

If the file doesn't have an extenion, I need to rename the file with .txt extension. For example Rpt200 will become Rpt200.txt

Please advice.

Thanks
Sun
Reply With Quote
Forum Sponsor
  #2  
Old 11-27-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Something like...

Code:
case `basename "$filename"` in
*.* )  
         echo has an extension
       ;;
* )
        echo does not have an extension
        filename="$filename.txt"
       ;;
esac
Reply With Quote
  #3  
Old 08-29-2008
RahulJoshi's Avatar
Registered User
 

Join Date: Aug 2008
Location: PUNE
Posts: 85
for f in `ls |grep -v *.*`;do
> mv "$f" "$f".txt
> done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:18 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0