Getting a file name from input file | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Getting a file name from input file

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-19-2013
leghorn leghorn is offline
Registered User
 
Join Date: May 2013
Last Activity: 27 August 2013, 4:15 AM EDT
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Getting a file name from input file

Hi

suppose I run my script using an argument (abc.xyz)
i want to strip the extension off nad just use the file name for further manipulations.

any ideas ?


~thanks
Sponsored Links
    #2  
Old Unix and Linux 08-19-2013
Jotne's Unix or Linux Image
Jotne Jotne is offline
Registered User
 
Join Date: Dec 2010
Last Activity: 20 September 2014, 2:08 AM EDT
Posts: 1,040
Thanks: 62
Thanked 216 Times in 204 Posts

Code:
echo "abc.xyz" | awk -F. '{print $1}'
abc

Sponsored Links
    #3  
Old Unix and Linux 08-19-2013
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 26 March 2015, 1:39 PM EDT
Location: Chennai, India
Posts: 443
Thanks: 22
Thanked 70 Times in 68 Posts

Code:
echo ${1%.*}

where $1 is the first argument passed to the script. If you are storing the argument in a variable, you can use


Code:
echo ${FILENAME%.*}

where FILENAME is the variable which stores the argument passed.
    #4  
Old Unix and Linux 08-19-2013
leghorn leghorn is offline
Registered User
 
Join Date: May 2013
Last Activity: 27 August 2013, 4:15 AM EDT
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
how about this ??

Code:
fullname="$1"
echo $fullname
name= "$fullname" | cut -f1 -d"."
echo $name


echo fullname works
bt cut command isnt working

what do i do ?

---------- Post updated at 03:23 PM ---------- Previous update was at 03:19 PM ----------

and what about this ??

malo901_cp-link_0807_020.csv

what If I want only cp-link out of it ??

Last edited by Franklin52; 08-19-2013 at 07:30 AM.. Reason: Please use code tags
Sponsored Links
    #5  
Old Unix and Linux 08-19-2013
krishmaths krishmaths is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 26 March 2015, 1:39 PM EDT
Location: Chennai, India
Posts: 443
Thanks: 22
Thanked 70 Times in 68 Posts
Replace name= "$fullname" | cut -f1 -d"." with


Code:
name=$(echo "$fullname" | cut -f1 -d".")

---------- Post updated at 03:27 PM ---------- Previous update was at 03:24 PM ----------


Code:
echo "malo901_cp-link_0807_020.csv" | cut -d"_" -f 2

Sponsored Links
    #6  
Old Unix and Linux 08-19-2013
leghorn leghorn is offline
Registered User
 
Join Date: May 2013
Last Activity: 27 August 2013, 4:15 AM EDT
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks all Unix or Linux Image
Sponsored Links
    #7  
Old Unix and Linux 08-19-2013
prasperl prasperl is offline
Registered User
 
Join Date: Jun 2009
Last Activity: 26 December 2013, 10:26 AM EST
Posts: 68
Thanks: 0
Thanked 1 Time in 1 Post
There is a simpler way

If you always know the extension and if it static..says extension is always xyz then you can use 'basename'

>basename abc.xyz .xyz
abc
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Installing a bin file by taking input from a properties file coolmohere Shell Programming and Scripting 1 12-06-2012 02:35 PM
Script to delete files with an input for directories and an input for path/file *ShadowCat* Shell Programming and Scripting 3 06-28-2012 09:16 PM
12. If an 88 Record with BAI Code 902 was found on input file and not written to Output file, re sgoud UNIX for Dummies Questions & Answers 0 07-06-2011 07:30 AM
Need script to take input from file, match on it in file 2 and input data darkoth Shell Programming and Scripting 1 11-03-2009 10:53 AM
Reading specific contents from 1 input files and appending it to another input file sksahu Shell Programming and Scripting 5 01-14-2009 05:09 AM



All times are GMT -4. The time now is 12:14 PM.