The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > 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 06:43 AM
How to get file extension shirleyeow Shell Programming and Scripting 17 01-17-2008 08:40 AM
Stripping out the extension of a file name ramky79 Shell Programming and Scripting 2 12-27-2006 02:25 PM
default extension of file rujupriya UNIX for Dummies Questions & Answers 2 05-17-2006 10:49 AM
One Last Question about Core Files (distinguish) URGENT TRUEST Shell Programming and Scripting 2 02-18-2003 04:14 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-12-2007
tbeghain tbeghain is offline
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
  #2 (permalink)  
Old 06-13-2007
johnf johnf is offline
Registered User
  
 

Join Date: May 2006
Location: England
Posts: 284
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
  #3 (permalink)  
Old 06-13-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Or...
Code:
VAR='myfile.txt'
pre=${VAR%.*}
pst=${VAR##*.}
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0