The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what is the distinguish between gmake and make? robin.zhu High Level Programming 10 10-10-2008 03:43 AM
How to get file extension shirleyeow Shell Programming and Scripting 17 01-17-2008 05:40 AM
Stripping out the extension of a file name ramky79 Shell Programming and Scripting 2 12-27-2006 11:25 AM
default extension of file rujupriya UNIX for Dummies Questions & Answers 2 05-17-2006 07:49 AM
One Last Question about Core Files (distinguish) URGENT TRUEST Shell Programming and Scripting 2 02-18-2003 01:14 PM

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

Join Date: Mar 2005
Location: Paris (France)
Posts: 6
distinguish the extension of a file

Hello,

In a script shell, I have a variable containing the name of a file and I would like to distinguish the name from the extention of the file. For example, the file 'myfile.txt' is in a variable called $VAR. How can I obtain 2 variables, one with 'myfile' and the other with 'txt' ?
Thank you
Reply With Quote
Forum Sponsor
  #2  
Old 06-13-2007
Registered User
 

Join Date: May 2006
Location: England
Posts: 265
Script test

#!/bin/ksh
name=$1
pre=`echo $name | cut -f 1 -d .`
pst=`echo $name | cut -f 2 -d .`
echo $pre
echo $pst

To run type

./test test.txt

Output

test
txt
Reply With Quote
  #3  
Old 06-13-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Or...
Code:
VAR='myfile.txt'
pre=${VAR%.*}
pst=${VAR##*.}
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 06:51 PM.


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