[CLUE-Tech] sed help

marcus hall marcus at tuells.org
Wed Jan 14 12:47:35 MST 2004


On Tue, Jan 13, 2004 at 05:32:35PM -0700, David Willson wrote:
> This works at the command-line:
> >echo "/home/david/.kde" | sed -e s/"\/home\/david"/"\/backups\/david"/
> /backups/david/.kde

> Now, how do I make it work in a script?

> Ultimately, I want something like this:
> find /home/david -type d -exec [! -d `sed -e
> s/'/home/david'/'/home/backups/david'/` ] echo "Error: Directory no found!"

Try this:

find /home/david -type d | sed 's#/home#/backups#'

Since you are only finding /home/david, all you really have to change is
/home => /backups.

Now, if you want to do some processing with the directories, you might want
to have both paths at hand at the same time.  If so, try this:

find /home/david -type d | while read h
do	b=/backups${h#/home}
	## Do whatever processing on the directories here
	## $h has the path to the directory in /home,
	## $b has the path to the directory under /backups
done

marcus hall



More information about the clue-tech mailing list