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 do i check whether a file has extension? sunday8 Shell Programming and Scripting 2 1 Week Ago 06:58 PM
How to get file extension shirleyeow Shell Programming and Scripting 17 01-17-2008 04: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 11:01 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
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-27-2006
Registered User
 

Join Date: Nov 2006
Posts: 38
Check file extension

Hi ,
I am FTPing the file. Once the file is FTPied I need to check whether that file currently transferred is of .xls and I need to convert the same to a flat file. What command to use to find the extension of the file?.

Thanks
Mahalakshmi.A
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-27-2006
Registered User
 

Join Date: Dec 2006
Posts: 16
Fiel Extension

Hi Maha,

Prob this shud help u.

/scripts/scr-bk-04-dec:>var=temp.cts
/scripts/scr-bk-04-dec:>echo $var | cut -d "." -f2
cts
/scripts/scr-bk-04-dec:>

Thanks,
Sharif.S
Reply With Quote
  #3 (permalink)  
Old 12-27-2006
Registered User
 

Join Date: Nov 2006
Posts: 38
Thanks sharif. Can u explain me about this cut command. What does f2 and d mean?.
Reply With Quote
  #4 (permalink)  
Old 12-27-2006
Registered User
 

Join Date: Jul 2006
Posts: 189
echo a.b.xls | awk -F"." '{ print $NF }'

it will alway give you extension whether file name contain more than 1 dot (.)


------------------
Ajay
Reply With Quote
  #5 (permalink)  
Old 12-27-2006
Registered User
 

Join Date: Dec 2006
Posts: 16
Cut Command

Cut :

Purpose : STrips/Cuts the required part from the passed input text
Usage:
cut -d "<value> -f <value> or -c <value>

-d = Delimiter
Seperator using wich u want divide ur text, Like "ABC,DEF" here , can be used as delimiter.

-f = field num

This is similar to column numbers. Inthe abv example ABC is field 1 and DEF is field# 2 if input is divided using comma.

-c = Character

cut -c 1,3

this will cut between 1st character to 3rd char.


Hope u understood wat i tried say.

Thanks,
Sharif.S
Reply With Quote
  #6 (permalink)  
Old 12-27-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Using ksh built-in:
Code:
file="foo.bar.baz.quux"
echo ${file##*.}
Reply With Quote
  #7 (permalink)  
Old 12-27-2006
Registered User
 

Join Date: Nov 2006
Posts: 38
Thanks all of you for all your replies. It all worked fine and I am using the command which suits the requirement.

Regards
Mahalakshmi.A
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:22 AM.


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

Content Relevant URLs by vBSEO 3.2.0