stripping server name from path


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers stripping server name from path
# 1  
Old 04-25-2006
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.
# 2  
Old 04-25-2006
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}

# 3  
Old 04-25-2006
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?
# 4  
Old 04-25-2006
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.
# 5  
Old 04-25-2006
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to access file path from another server?

Hi there, Say I have Server A and B, how do I configure A with path aaa/bbb/ccc to be able to access by Server B with aaa/bbb/ccc/<content> (9 Replies)
Discussion started by: alvinoo
9 Replies

2. Shell Programming and Scripting

Wait for file to get copied in server path and then proceed

Hi, I have a requirement to create below script: Script must run infinitely in background. It will check a particular type of file to be copied in specific folder of server Script must wait till any file gets fully copied ..(important) and then It will read that file Experts please... (4 Replies)
Discussion started by: Vikash163
4 Replies

3. Shell Programming and Scripting

Permission to Oracle server to create a directory in a particular path

i need to give permission to ORACLE SERVER to create a directory in a particular path. How to do it?Oracle server is installed on SOLARIS (16 Replies)
Discussion started by: rafa_fed2
16 Replies

4. Shell Programming and Scripting

Copy down remote files and rename them to include the server name with full path

I need to pull down a good bit of files for another support team for an upgrade project. I have a server.list with all of the server names. I need to do two parts: FIRST: I have this example, but it does not list the server name in front of each line. #! /bin/bash for server in $(<... (10 Replies)
Discussion started by: asnatlas
10 Replies

5. Shell Programming and Scripting

ssh user@server ' cd path;j=0; for i in *;do;d=`du -sh $i | awk '{print( $1 )}'`;p=$d'|'$i;j=`expr $

Please help me to resolve below the issue in script ssh user@server ' cd path;j=0; for i in *;do;d=`du -sh $i | \ awk '{print( $1 )}'`;p=$d'|'$i;j=`expr $j + 1 `;arr=$p;echo ${arr};done' (1 Reply)
Discussion started by: SAUD PASHA
1 Replies

6. Shell Programming and Scripting

Need help: Script to report timestamp of directories in a specific path from multiple Linux server

Need help Please help on how to write a script which can echo timestamp, size of subdirectories in a specific path from multiple Linux servers to a text file. I can ssh with a common user to all the servers from a build box. Basic idea what I had was: ssh <commonuser>@<each box> cd... (1 Reply)
Discussion started by: sudhichadaga
1 Replies

7. Shell Programming and Scripting

Solaris Server dectects EMC dead path and send mail immediately

taus-itcapp1#powermt display dev=all Pseudo name=emcpower0a CLARiiON ID=APM00105201788 Logical device ID=60060160B2202B001094F0E0AF5CE011 state=alive; policy=CLAROpt; priority=0; queued-IOs=0; Owner: default=SP A, current=SP A Array failover mode: 1 ... (6 Replies)
Discussion started by: orafup
6 Replies

8. Ubuntu

Ubuntu samba server path

Hi, I can see a folder is mounted in my Ubuntu 8.04 machine through samba share. But, I could not find it out its actual location in the disk. If I issue the command sudo smbclient -L user its listing the folder as 'sharename' and 'type' as disk So, anyone help me how can I locate the... (0 Replies)
Discussion started by: royalibrahim
0 Replies

9. UNIX for Dummies Questions & Answers

Stripping down binaries

Hello, I am the CEO of Grand Tech Corporation. We are launching Linux NT and forgive me, but I do not know how to strip binaries down in Mandriva Linux. Can someone tell me a way to?:b: (2 Replies)
Discussion started by: Linux NT
2 Replies

10. UNIX for Dummies Questions & Answers

Assign name to path in unix server

How can I make it so if someone types in "Manager" in the url box in their browser, it will bring them to the path /var/www/html/resourcedb/index.html? its currently viewable by going to the serveripaddress/resourcedb/index.html, but I want it to be shorter so when you are connected to the... (2 Replies)
Discussion started by: Zombie
2 Replies
Login or Register to Ask a Question