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
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
variables don't work for inline "su" script joekreif UNIX for Advanced & Expert Users 3 04-18-2007 01:30 PM
how could i make a program mixed with many "|", "<" and ">" strugglingman High Level Programming 2 04-29-2006 05:11 AM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 01:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-07-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
How to omit "./" store in variables

Good Morning All,

I did a find command to search for files and stored it in a variable. I then will use the variable to get the file name and "get" it from another server (using ftp). The problem I have is, filenames are stored with "./" in the variable. when I try to get it, I get an error because "./" does not work in the other server i.e. windows NT.

How do I just extract the filename without the "./" as stored in the variables.

Example :
Contents of FILES variable
./test.txt ./process.txt ./order.txt

I only want to get values of $FILES without "./".

Thanks a lot!
Reply With Quote
Forum Sponsor
  #2  
Old 07-07-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Add this to your script.

Suppose VARIABLE holds all the filenames that came out of the find.

Code:
RESULT=`echo $VARIABLE | sed -e 's/\.\///g'`
$RESULT should hold all the values without the ./

Havn't tested it tho'.

Vino
Reply With Quote
  #3  
Old 07-07-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
it worked!

Thank you very much!!!!
Reply With Quote
  #4  
Old 07-07-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
RESULT=`echo basename $VARIABLE`
is also a choice.
Reply With Quote
  #5  
Old 07-07-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
what is a basename? a built in unix function?
Reply With Quote
  #6  
Old 07-07-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
basename is a external command like sed. However:
RESULT=`basename $VARIABLE`
is the syntax. With modern shells, you can use builtins to do this:
x=${x#./}
Reply With Quote
  #7  
Old 07-07-2005
Registered User
 

Join Date: Jun 2005
Location: St. Louis, MO
Posts: 32
Thanks!

Is it also the same if I do :

x=${x#*./}?

Another curios question. In processing variables, is it always a good practive to enclosed it with curly braces?

Thanks a lot!

Joseph
ps. What is a good unix programming book
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:58 PM.


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

Content Relevant URLs by vBSEO 3.2.0