![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Something like...
Code:
case `basename "$filename"` in
*.* )
echo has an extension
;;
* )
echo does not have an extension
filename="$filename.txt"
;;
esac
|
|
#3
|
||||
|
||||
|
for f in `ls |grep -v *.*`;do
> mv "$f" "$f".txt > done |
||||
| Google The UNIX and Linux Forums |