The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
stripping white space... Zak Shell Programming and Scripting 7 10-09-2007 04:41 AM
$PWD shows absolute path vs path w/symbolic links kornshellmaven Shell Programming and Scripting 3 06-13-2007 09:15 AM
stripping out certain charecters mervin2006 Shell Programming and Scripting 4 12-01-2006 05:22 AM
vi - replacing a relative path with absolute path in a file Yinzer955i UNIX for Dummies Questions & Answers 2 09-07-2006 08:47 AM
stripping last character from end of each line hcclnoodles UNIX for Dummies Questions & Answers 6 11-21-2005 05:35 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-25-2006
Registered User
 

Join Date: Apr 2006
Posts: 8
Question stripping server name from path

can anyone help me with stripping an absolute filepath? I did a search on this topic but didnt find anything but maybe I didn't look hard. Anyway, would really appreciate it if anyone could help me. I am a new unix user so this might be a simple issue but I am stuck, don't really understand the use of 'grep'

here is the path that I have (dvrg12 is the server name) and this script is on the same server too

//dvrg12/usr/users/user_name/folder1/folder2/file_name

ideally I want to return only "/user_name/folder1/folder2/filename" and I obviously know the user_name.

thought of using a regular expression to search for the pattern of the server name since its always going to be the same. the format of the server name will be as follows (could be wrong):

[a-z]\{4\}[0-9]\{2\} == dvrg12 ?? if I could find the match and return everything after it then it would be ok from there but thats where I am stuck.

thanks in advance...could this be as simple as using the cut command? although that would only work if the path I was given always started with 2 forward slashes but what if it starts with only 1 forward slash or starts with no foraward slash?

D.
Reply With Quote
Forum Sponsor
  #2  
Old 04-25-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Code:
//dvrg12/usr/users/user_name/folder1/folder2/file_name
Would the path //any-server-name/usr/users always remain the same ?

If the server name changes, try this.

Code:
#! /bin/ksh
server=//dvrg12/usr/users/user_name/folder1/folder2/file_name
echo ${server#*users}
It gives,

Code:
/user_name/folder1/folder2/file_name
Else this would also do.
Code:
#! /bin/ksh
server=//dvrg12/usr/users/user_name/folder1/folder2/file_name
echo ${server#//dvrg12/usr/users}
Reply With Quote
  #3  
Old 04-25-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Quote:
Originally Posted by Ecclesiastes
can anyone help me with stripping an absolute filepath? I did a search on this topic but didnt find anything but maybe I didn't look hard. Anyway, would really appreciate it if anyone could help me. I am a new unix user so this might be a simple issue but I am stuck, don't really understand the use of 'grep'

here is the path that I have (dvrg12 is the server name) and this script is on the same server too

//dvrg12/usr/users/user_name/folder1/folder2/file_name

ideally I want to return only "/user_name/folder1/folder2/filename" and I obviously know the user_name.

thought of using a regular expression to search for the pattern of the server name since its always going to be the same. the format of the server name will be as follows (could be wrong):

[a-z]\{4\}[0-9]\{2\} == dvrg12 ?? if I could find the match and return everything after it then it would be ok from there but thats where I am stuck.

thanks in advance...could this be as simple as using the cut command? although that would only work if the path I was given always started with 2 forward slashes but what if it starts with only 1 forward slash or starts with no foraward slash?

D.
what are the possible inputs?
//dvrg12/usr/users/user_name/folder1/folder2/file_name
/dvrg12/usr/users/user_name/folder1/folder2/file_name
dvrg12/usr/users/user_name/folder1/folder2/file_name

Is there always going to be '/usr/users' in the path?
Reply With Quote
  #4  
Old 04-25-2006
Registered User
 

Join Date: Apr 2006
Posts: 8
Quote:
Originally Posted by vgersh99
what are the possible inputs?
//dvrg12/usr/users/user_name/folder1/folder2/file_name
/dvrg12/usr/users/user_name/folder1/folder2/file_name
dvrg12/usr/users/user_name/folder1/folder2/file_name

Is there always going to be '/usr/users' in the path?

yes the '/usr/users' is always going to be the same but I think the solution above will work just as well and I will try it now.

Thanks.

D.
Reply With Quote
  #5  
Old 04-25-2006
Registered User
 

Join Date: Apr 2006
Posts: 8
Quote:
Originally Posted by vino
Code:
//dvrg12/usr/users/user_name/folder1/folder2/file_name
Would the path //any-server-name/usr/users always remain the same ?

If the server name changes, try this.

Code:
#! /bin/ksh
server=//dvrg12/usr/users/user_name/folder1/folder2/file_name
echo ${server#*users}
It gives,

Code:
/user_name/folder1/folder2/file_name
Else this would also do.
Code:
#! /bin/ksh
server=//dvrg12/usr/users/user_name/folder1/folder2/file_name
echo ${server#//dvrg12/usr/users}
thanks for the help, solution works perfectly just had to tailor it to the rest of my script

Ecclesiates
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:45 AM.


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