02-01-2010
SED: Removing Filenames From Paths
I'm using a script with a lot of SED commands, in conjunction with grep, cut, etc. I've come up against a wall with a particular road block:
I output a file from an SVN registry that gives me a list of files. The list consists of a variable number of lines that contain a path/file. The paths are not a consistent length, hence a variable number of /'s in them. I pipe this output to a file and manipulate that file to create a list of source files for a copy routine I'm writing.
I'd like to be able to read the path line(s) from this file and remove the file name itself thus replicating just the path that I can feed to an rcp command. But I've been hitting a wall as to how to detect the last slash in the line.
from
/u/dir1/dir2/dir3/file
/u/dir1/dir2/file
/u/dir1/file
to
/u/dir1/dir2/dir3/.
/u/dir1/dir2/.
/u/dir1/.
Or blank instead of periods.
I can show you my work / first tries if need be, but it resides in a lab that is cut off from public access, ie: the internet, so I'd have to retype it and thus, why I don't have my first examples here to look at.
Any sort of help would be appreciated, whether it be pointing me to another link (I've been searching this site for quite some time) I haven't found yet or what not.
Thanks folks! -Bruce
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi there,
I'm pretty new to UNIX and have tried trawling through this forum to find an answer to what I want to try to do, which I'm sure is very simple but I don't know how to do it.
What I have a a folder that contains multiple files that I have copied from Windows and I want to remove the... (5 Replies)
Discussion started by: johnmcclintock
5 Replies
2. Shell Programming and Scripting
Hi,
I have a file with the text below. How do i remove the character "%" from the text file using sed ? Can anybody help ?
0%
68%
72%
0%
54%
33%
75%
24%
6%
59%
77%
77%
33% (6 Replies)
Discussion started by: Raynon
6 Replies
3. UNIX for Dummies Questions & Answers
Hi,
I've been searching for a quick way to do this with sed, but to no avail.
I have a file containing a long series of (windows) file paths that are separated by the pattern '@'. I would like to extract each file path so that I can later assign a variable to each path.
Here is the file:... (2 Replies)
Discussion started by: nixjennings
2 Replies
4. Shell Programming and Scripting
Hey folks
My problem is simple. For my first stash of movies, I used a naming convention of YEAR_MOVIE_NAME__QUALITY/ for each movie folder. For example, if I had a 1080p print of Minority Report, it would be 2002_Minority_Report__1080p/.
The 2nd time around, I changed the naming convention... (4 Replies)
Discussion started by: ksk
4 Replies
5. UNIX for Dummies Questions & Answers
The task: remove undesirable characters from filenames.
Restrictions: Must use basic RE, base utilities (non-GNU) and /bin/sh (ash). No ksh, zsh, perl, etc.
Below is what I've come up with. It seems to work OK but I'm open to shorter, more efficient alternatives.
Inside the square... (4 Replies)
Discussion started by: uiop44
4 Replies
6. Shell Programming and Scripting
I have a problem mounting images because of the spaces in the filenames. Does anyone know how to rename files by removing the spaces with the find command?
find Desktop/$dir -name "*.dmg" -print -exec ??? (4 Replies)
Discussion started by: ianebaj
4 Replies
7. Shell Programming and Scripting
I have a source text file that contains something like this:
<start_template>
bool function( void *<var_name> )
{
// Blah Blah
}
</start_template>
Following is used to remove this template from source file.
template=$(sed -n -e '/<start_template>/,/<\/start_template>/{... (4 Replies)
Discussion started by: gee22
4 Replies
8. Solaris
Hi,
One of our Solaris servers was peviously zoned and connected to 2 seperate arrays, one HP and the other EMC. The server is now only connected to the EMC. The sever has x2 single port HBA's.
When running cfgadm I see the following:
root@qwicprod /dev/rdsk]# cfgadm -al
Ap_Id Type... (6 Replies)
Discussion started by: jamba1
6 Replies
9. Shell Programming and Scripting
I have a file and I want to remove quotes from the word " ` " through sed command but unable to remove
I am using below command
sed s/"`XYZ`"/"ZXY"/g file1.txt > file2.txt
But this is not working. How can we remove "`" through sed command (2 Replies)
Discussion started by: kaushik02018
2 Replies
10. Shell Programming and Scripting
I am able to list all the filenames under a directory & its sub-directories except blent.tar on Linux
find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev
Desired Output:
THIRDPARTYLICENSEREADME.txt
javaws
libjavaplugin_oji.so
libjavaplugin_oji.so... (3 Replies)
Discussion started by: mohtashims
3 Replies