Check file extension


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check file extension
# 1  
Old 12-27-2006
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
# 2  
Old 12-27-2006
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
# 3  
Old 12-27-2006
Thanks sharif. Can u explain me about this cut command. What does f2 and d mean?.
# 4  
Old 12-27-2006
echo a.b.xls | awk -F"." '{ print $NF }'

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


------------------
Ajay
# 5  
Old 12-27-2006
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
# 6  
Old 12-27-2006
Using ksh built-in:
Code:
file="foo.bar.baz.quux"
echo ${file##*.}

# 7  
Old 12-27-2006
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rename specific file extension in directory with match to another file in bash

I have a specific set (all ending with .bam) of downloaded files in a directory /home/cmccabe/Desktop/NGS/API/2-15-2016. What I am trying to do is use a match to $2 in name to rename the downloaded files. To make things a more involved the date of the folder is unique and in the header of name... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. UNIX for Dummies Questions & Answers

File Extension Missing in file-$var.csv

I'm afraid this is a silly question but I can't figure it out. I have a script like so... echo "Enter DRDL Signature Version Number" read DRDL_Number mv signature_output.csv SERVICE_OBJECTS_S-$DRDL_Number.csv The resultant filename does not contain the .csv as follows.... (3 Replies)
Discussion started by: Cludgie
3 Replies

3. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

4. Shell Programming and Scripting

Check for file with a particular extension in a particular directory

Hi, I have a directory which I am passing in my script as a parameter. Parameter name has been set to $TCH_FILE_DIRECTORY. I want to know if there's atleast 1 (or more) files in this directory with the extension '.tch'. How can I find this using ksh. (4 Replies)
Discussion started by: Bhavesh Sharma
4 Replies

5. Shell Programming and Scripting

Getting the file extension

I have a file n06-z30-sr65-rgdt0p25-varp0.25-8x6drw-test.cmod and I want to get the extension. At the moment I have set filextension = `echo $f | awk 'BEGIN {FS="."} {print $2}'` which of course does not work as there is a point in varp0.25 (13 Replies)
Discussion started by: kristinu
13 Replies

6. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies

7. UNIX for Dummies Questions & Answers

About the file extension

Hi everyone, Can we know that which type of file is there without opening a file thanks in advance.... kunal patil (3 Replies)
Discussion started by: kunalpatil09
3 Replies

8. Shell Programming and Scripting

How to check that passed parameters all have the same extension?

$ ls monkey.txt banana.csv tree.txt $ myscript monkey.txt tree.txt All extensions ARE alike. $ myscript *txt All extensions ARE alike. $ myscript monkey.txt banana.csv All extensions are NOT alike. $ myscript * All extensions are NOT alike. My brain has given up; what's the simplest... (11 Replies)
Discussion started by: cs03dmj
11 Replies

9. Shell Programming and Scripting

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. ... (2 Replies)
Discussion started by: sunday8
2 Replies

10. Shell Programming and Scripting

filename extension check - regular expression

How to compare the file name for "zip" or "ZIP" extension. I can put one more || condition to check the upper case in the below: if ]; then Is there any better way to compare using regular expressions. Thx in advance. (4 Replies)
Discussion started by: devs
4 Replies
Login or Register to Ask a Question