A way to print only part of directory path


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users A way to print only part of directory path
Prev   Next
# 2  
Old 01-20-2018
Your desired output is inconsistent. You want the trailing /, or not?
Code:
sed "s|\(.*/logs\)[$/].*|\1|" # no
sed "s|\(.*/logs[$/]\).*|\1|" # yes

grep -o can do the same thing, probably more efficiently, but -o is possibly not portable, depending on where you plan to use it.
This User Gave Thanks to Scott For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

What is the difference ../directory path and ./directory path in ksh?

What is the difference ../directory path and ./directory path in ksh? (1 Reply)
Discussion started by: TestKing
1 Replies

2. UNIX for Beginners Questions & Answers

Convert Relative path to Absolute path, without changing directory to the file location.

Hello, I am creating a file with all the source folders included in my git branch, when i grep for the used source, i found source included as relative path instead of absolute path, how can convert relative path to absolute path without changing directory to that folder and using readlink -f ? ... (4 Replies)
Discussion started by: Sekhar419
4 Replies

3. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

4. Shell Programming and Scripting

print all filenames in directory with path to another file

hi, i have a directory at /path/unix with the following files 1.txt 2.txt 3.txt 4.txt I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be /path/home/filenames.txt with contents /path/unix/1.txt... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

5. 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

6. Shell Programming and Scripting

Print directory name along with their path

Can any one tell me that how can i print all directory with their path in a given parent directory. i.e. parent directory /home/usr/ Now this shoe directory may contain sevral directory /home/usr dir1/ dir1.1/ dir1.2/ dir2 dir2.1/ dir2.2/ ... (5 Replies)
Discussion started by: jadoo_c2
5 Replies

7. Shell Programming and Scripting

Howto Print File Path or Print the Filename

I'm trying to clean up my samba share and need to print the found file or print the path of the image it tried to searched for. So far I have this but can't seem to get the logic right. Can anyone help point me in the right direction? for FILE in `cat list`; do if ; then ... (1 Reply)
Discussion started by: overkill
1 Replies

8. Shell Programming and Scripting

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, ... (3 Replies)
Discussion started by: tiger66
3 Replies

9. Shell Programming and Scripting

How do I get awk to print a " in it's print part?

The line is simple, use " '{ print $1"]"$2"\"$3THE " NEEDS TO GO HERE$4 }' I've tried \", "\, ^" and '"" but none of it works. What am I missing? Putting in the [ between $1 and $2 works fine, I just need to do the same with a ". Thanks. (2 Replies)
Discussion started by: LordJezo
2 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
SVN_DIFF(3)								 1							       SVN_DIFF(3)

svn_diff - Recursively diffs two paths

SYNOPSIS
array svn_diff (string $path1, int $rev1, string $path2, int $rev2) DESCRIPTION
Recursively diffs two paths, $path1 and $path2. Note This is not a general-purpose diff utility. Only local files that are versioned may be diffed: other files will fail. PARAMETERS
o $path1 - First path to diff. This can be a URL to a file/directory in an SVN repository or a local file/directory path. Note Relative paths will be resolved as if the current working directory was the one that contains the PHP binary. To use the calling script's working directory, use realpath(3) or dirname(__FILE__). Warning If a local file path has only backslashes and no forward slashes, this extension will fail to find the path. Always replace all backslashes with forward slashes when using this function. o $rev1 - First path's revision number. Use SVN_REVISION_HEAD to specify the most recent revision. o $path2 - Second path to diff. See $path1 for description. o $rev2 - Second path's revision number. See $rev1 for description. RETURN VALUES
Returns an array-list consisting of two streams: the first is the diff output and the second contains error stream output. The streams can be read using fread(3). Returns FALSE or NULL on error. The diff output will, by default, be in the form of Subversion's custom unified diff format, but an external diff engine may be used depending on Subversion's configuration. NOTES
Warning This function is EXPERIMENTAL. The behaviour of this function, its name, and surrounding documentation may change without notice in a future release of PHP. This function should be used at your own risk. EXAMPLES
Example #1 Basic example This example demonstrates the basic usage of this function, and the retrieval of contents from the stream: <?php list($diff, $errors) = svn_diff( 'http://www.example.com/svnroot/trunk/foo', SVN_REVISION_HEAD, 'http://www.example.com/svnroot/branches/dev/foo', SVN_REVISION_HEAD ); if (!$diff) exit; $contents = ''; while (!feof($diff)) { $contents .= fread($diff, 8192); } fclose($diff); fclose($errors); var_dump($contents); ?> The above example will output: Index: http://www.example.com/svnroot/trunk/foo =================================================================== --- http://www.example.com/svnroot/trunk/foo (.../foo) (revision 23) +++ http://www.example.com/svnroot/branches/dev/foo (.../foo) (revision 27) // further diff output Example #2 Diffing two revisions of a repository path This example implements a wrapper function that allows a user to easily diff two revisions of the same item using an external repository path (the default syntax is somewhat verbose): <?php function svn_diff_same_item($path, $rev1, $rev2) { return svn_diff($path, $rev1, $path, $rev2); } ?> Example #3 Portably diffing two local files This example implements a wrapper function that portably diffs two local files, compensating for the realpath(3) fix and the back- slashes bug: <?php function svn_diff_local($path1, $rev1, $path2, $rev2) { $path1 = str_replace('\', '/', realpath($path1)); $path2 = str_replace('\', '/', realpath($path2)); return svn_diff($path1, $rev1, $path2, $rev2); } ?> SEE ALSO
SVN documentation on svn diff. PHP Documentation Group SVN_DIFF(3)