The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find complete path of a file in unix yahoo! UNIX for Dummies Questions & Answers 5 07-25-2008 03:59 AM
how to find the path of a file? wrapster Shell Programming and Scripting 3 03-26-2008 10:31 AM
command to find the path of a file abhilashnair UNIX for Dummies Questions & Answers 3 02-17-2008 07:15 PM
to find the file with full path surjyap Shell Programming and Scripting 5 01-18-2008 03:26 PM
Find a file in sub-directories.. o/p just the path pranavagarwal Shell Programming and Scripting 3 11-23-2007 01:50 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 3.00 average. Display Modes
  #1 (permalink)  
Old 10-28-2008
samir_standing samir_standing is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 11
Find a path of a specific file

Hi,

A variable value is /home/samir/datas/data.txt
I want /home/samir/datas.
How can I get that.
  #2 (permalink)  
Old 10-29-2008
u4xmnsk u4xmnsk is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 6
Could you explain it?

Provide some more information about what exactly you want? I didn't get what your asking..
  #3 (permalink)  
Old 10-29-2008
samir_standing samir_standing is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 11
The exact path of data.txt i.e. /home/samir/datas/data.txt
is stored in a variable.

I want /home/samir/datas i.e. path not includes the filename
to estract and store into another variable.

Simply I want to cut /home/samir/datas from /home/samir/datas/data.txt
  #4 (permalink)  
Old 10-29-2008
samir_standing samir_standing is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 11
Can anyone help me
how to extract /home/samir/datas
from /home/samir/datas/data.txt
  #5 (permalink)  
Old 10-29-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by samir_standing View Post
Can anyone help me
how to extract /home/samir/datas
from /home/samir/datas/data.txt
Code:
path=$(dirname /home/samir/datas/data.txt)
  #6 (permalink)  
Old 10-29-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,088
Code:
echo "/home/samir/datas/data.txt" | sed 's/\(.*\/\)\(.*\)/\1/'
  #7 (permalink)  
Old 10-29-2008
sai21 sai21 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 27
Hope ...this will work out

echo $TMPVAR | awk -F / '{ for (i=1;i<NF;i++) printf $i"/"; }'

Where TMPVAR contains the path of the file.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0