[CLUE-Tech] sed help

Dale K. Hawkins dhawkins at cdrgts.com
Wed Jan 14 13:28:00 MST 2004


"David Willson" <dlwillson at thegeek.nu> writes:

> I'm going crazy here.
>
> I want to take strings returned by 'find' and replace the folder-name I was
> searching in with another folder-name, but sed is ~not~ behaving as I want
> it to.
> 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!"

sed has this very cool feature for just this sort of problem.  You do
not need to use slashes '/'.  Instead use some more convenient
character:

$ echo $PWD | sed 's#dhawkins#backups/dhawkins#g'

But since I really do not know what you intend to do with the new
names, I cannot offer much better advice.  There might be tools which
already do what you want like rsync or cvs, etc.

-Dale



More information about the clue-tech mailing list