retrieve part of file path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting retrieve part of file path
# 1  
Old 03-23-2009
retrieve part of file path

Hi
I am trying to use sed to retrieve part of my html file's path. I am having a hard time getting what I want. Could someone give me some help?

I want to retrieve the section after html and before the file name
For example if I have the following,
/home/folder1/html/home/house/Home.html@@/main/

What do I need to do to get
home/house

I have tried
Code:
echo /home/folder1/html/home/house/Home.html@@/main/ | sed 's/.*\/html\/\*.*\.html\).*\/1/'

but I can't remove the file name.

Any help will be greatly appreciated

Last edited by Franklin52; 03-23-2009 at 05:24 AM.. Reason: adding code tags
# 2  
Old 03-23-2009
Code:
echo "/home/folder1/html/home/house/Home.html@@/main/" | sed 's/\(.*\/html\)\(.*\/\)\(.*\/\)\(.*@\/.*\/\)/\2\3/'


Last edited by Franklin52; 03-23-2009 at 05:22 AM.. Reason: adding code tags
# 3  
Old 03-23-2009
Code:
echo "/home/folder1/html/home/house/Home.html@@/main/" | awk -F / '{ printf ("%s/%s",$5,$6)}'


Last edited by Franklin52; 03-23-2009 at 05:23 AM.. Reason: adding code tags
# 4  
Old 03-23-2009
Another sed solution, after ".*html/" it selects the words without a slash, 1 slash and the words before the next slash, unindepend of the length and the construction of the path:

Code:
sed 's!.*/html/\([^/]*\)\(/[^/]*\).*!\1\2!'

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

A way to print only part of directory path

Hi, So I struggled to find a solution to the following problem: I want to make sed print only part of multiple different paths. So lets say we have /path/path1/path2/logs/bla/blabla /path/path1/path2/path3/logs/yadda/yadda/yadda Can someone suggest a way to make sed or other... (5 Replies)
Discussion started by: dampio
5 Replies

2. Shell Programming and Scripting

How to retrieve a file from specific path using unix script?

Hi i'm new to shell script, i want to get the filename from specific location which i mentioned in my script. The scirpt should read the filename exactly using the following command "ls -ltr | tail -1". Could someone show me on this. Below is my script #!/bin/ksh PATH= /usr/ if then ... (4 Replies)
Discussion started by: fresher
4 Replies

3. Shell Programming and Scripting

Perl command to replace path part of variable

I'm trying to replace path which is part of variable inside script file: FROM: ABC_HOME=$ABC_ROOT/abc/1.0 TO: ABC_HOME=$ABC_ROOT/abc/1.5 I'm using this: perl -pi -e 's\ABC_HOME=$ABC_ROOT/abc/1.0\ABC_HOME=$ABC_ROOT/abc/1.5\g' /apps/scripts/test.sh This command is not working because... (2 Replies)
Discussion started by: djanu
2 Replies

4. Shell Programming and Scripting

Retrieve directory path from full file path through sh

Hi, I have a file abcd.txt which has contents in the form of full path file names i.e. $home> vi abcd.txt /a/b/c/r1.txt /q/w/e/r2.txt /z/x/c/r3.txt Now I want to retrieve only the directory path name for each row i.e /a/b/c/ /q/w/e/ How to get the same through shell script?... (7 Replies)
Discussion started by: royzlife
7 Replies

5. UNIX for Advanced & Expert Users

How do i use vi to substitute an expression that is part of a path?

Let say I have /home/user1/bin/ and i want it to be /root/bin I tried : s/\/home\/user1/user2/ but it can't find the pattern user1. I tried: s/*\/home\/user1*/user2/ as well same result many thanks (4 Replies)
Discussion started by: c00lsnoopy
4 Replies

6. Shell Programming and Scripting

taking a part of string from a given path

Hi I have two path as follows system/console/bin/code/sample/testfile.txt system/console/bin/database/files/new/dbfile.txt I need the output as code/sample in first case database/files/new in second case That is I am omitting system/console/bin and the filename(s) in both... (2 Replies)
Discussion started by: ssuresh1999
2 Replies

7. Shell Programming and Scripting

regex to select last part of a path

Hi all, I am learning the use of regular expression and I would like to know which regex can be used to select only the last part of a directory path name. Something like: /dir1/dir2/dir2 and I want to select the last /dir2 where dir2 can be any kind of string. Thanks a lot for your help.... (7 Replies)
Discussion started by: elric
7 Replies

8. Shell Programming and Scripting

how to retrieve a part of the word

Hi I have a word assigned to the variable, for example: A=TTOP Is there a way to remove the first letter from this word and assign the rest of the word to another variable, so the output would be like this: B=TOP Thanks a lot for any advice.... -A (2 Replies)
Discussion started by: aoussenko
2 Replies

9. UNIX for Dummies Questions & Answers

display full unix path as part of the command line

Hi all, Does anyone know how to ammend the .cshrc file in $HOME for your session to display the path as part of the command line? So that I dont need to keep on typing pwd to see where I am? thanks Ocelot (3 Replies)
Discussion started by: ocelot
3 Replies

10. Shell Programming and Scripting

getting the path part of an argument

Seems I'm inundating this forum with questions, but anyway: I am writing a script that should accept one and only one argument when called. That argument should designate a file, either with path/filename or just filename. Now to the difficult bit: I want to figure out a way to store... (9 Replies)
Discussion started by: ropers
9 Replies
Login or Register to Ask a Question