Extracting file name and finding extension of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting file name and finding extension of the file
# 1  
Old 06-07-2010
Extracting file name and finding extension of the file

Hi.,

How to extract the extension of a file which are present in the directory?. In my script I tried something like:

Code:
echo abc_ss_222_54.txt | awk -F"[_.]" '{print $5}'

But I din't got .txt echoed in console. Pl. suggest a solution for this.


And also, for finding a specific pattern of file, I did:

Code:
find `ls -lrt /tmp/vinay/act/files |grep "Jun  7"| awk '{print $9}'` "fdr_c_us_cons_*.[txt|done]"


Here I want to findout fdr_c_us_cons_*.[txt|done] type of file is present in the directory /tmp/vinay/act/files or not.

But it is displaying the o/p as :

Code:
 
find: cannot open fdr_c_us_cons_20100607_121212.txt: No such file or directory
.
.
.

How to resolve the above code to check the existense of the file?


Thank you.
# 2  
Old 06-07-2010
Code:
echo "abc_ss_222_54.txt" | awk -F '.' '{print $NF}'

Code:
ls -1 /tmp/vinay/act/files | grep -E 'fdr_c_us_cons_*.[txt|done]'

This User Gave Thanks to dr.house For This Post:
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. Shell Programming and Scripting

Finding file extension on C Shell script

I very new to C Shell. I am trying to do is read from Command line. Find the if the file is zip, .txt, symbloic link,pipe, unknow (if file is not zip, txt, sy....) here is what I what got so far. I am very stuck atm Please help me out : If the file is symblooc link what file is link to ... (12 Replies)
Discussion started by: madbull41
12 Replies

4. IP Networking

Issue File Extension is file Size

I am currently experiencing the file size being added to the file extension when transfering information from Command Line Client to a UNIX server. Does anyone know why this is happening and how do I stop the file size being added to the file extension. Example: football.pqt.11108... (1 Reply)
Discussion started by: Skeeterrock
1 Replies

5. 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

6. Shell Programming and Scripting

Help on extracting file with zipx extension

Please guide me in extracting a file with .zipx extension (3 Replies)
Discussion started by: mohan_xunil
3 Replies

7. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

8. Shell Programming and Scripting

CSH - finding files with the same file extension

Hey, I'm having a problem finding out if a directory holds any files with a certain file extension, for example .txt. I have tried: if (! -e "*.txt") and I've tried: set FILES=`ls *` echo "Found $FILES" foreach FILE ($FILES) if($FILE == "*.txt") And neither of... (2 Replies)
Discussion started by: amnesiaiom
2 Replies

9. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

10. UNIX for Dummies Questions & Answers

How to append a file extension to end of a file name??

Hi, I have a .txt file and it contains some file names.I want to append .gz extension to all the file names that are present within the .txt file. Input. aa.bb.Mar-20-2007 aa.cc.Mar-20-2007 Output aa.bb.Mar-20-2007.gz aa.cc.Mar-20-2007.gz Please help me with this command. ... (10 Replies)
Discussion started by: kumarsaravana_s
10 Replies
Login or Register to Ask a Question