[CLUE-Tech] Just a little help?
Ed Hill
ed at eh3.com
Wed Jan 14 22:38:58 MST 2004
On Wed, 2004-01-14 at 22:35, David Willson wrote:
> I got the hard part done. Or so it seems. I have written a script that will
> replace a 'source' directory's name in all the found directory-names with a
> target directory's name. Now, I want to test each line of output for
> directory-ness, and record the source directory that doesn't have a matching target.
>
> Help? Pretty-please?
Hi David,
Marcus Hall and I already sent you two perfectly good options that will
do exactly what you want. They are:
Option 1: (from Marcus): Use the bash "read" built-in (see his
previous email) to do something such as:
find /path1 -type d | sed -e 's|/path1|/path2|g' | while read i ; do
test ! -d $i && echo "cannot find $i"
done
Option 2: (adapted from my earlier email) similar to Marcus' idea:
find /path1 -type d | sed -e 's|/path1|/path2|g' | \
perl -e 'while(<>){if(! -d $_){print "Error: cannot find: $_";}};'
Really, your problem only warrants a simple little two- or three-line
script. You're putting way too much time/effort/typing into it...
Ed
> Script is quoted below.
>
> ----- Forwarded message from dlwillson at mailman.thegeek.nu -----
>
> #!/bin/bash
>
> # ~this~ takes two directories as arguments
> # and verifies that all folders in the first exist as folders in the second.
> # Author: David L. Willson, (303) 299-8042, DLWillson at TheGeek.NU
> # Created: 2004 JAN
>
> srce="/home/dlwillson/"
> dest="/backup/dlwillson/"
>
> # Validate directories
> if [ ! -d $srce ]
> then echo $srce "is not a directory" ; exit 1
> fi
> if [ ! -d $dest ]
> then echo $dest "is not a directory" ; exit 1
> fi
>
> # What I need to do next (escape the slashes):
> # $ echo "/home/dlwillson/.kde" | sed -e s/[/]/'\\\/'/g
> # \/home\/dlwillson\/.kde
>
> sedCmnd="s/[/]/\\\\\\//g"
> eSrce=`echo $srce | sed -e $sedCmnd`
> eDest=`echo $dest | sed -e $sedCmnd`
>
> # Echo variables back
> echo '$srce='$srce
> echo '$dest='$dest
> echo '$eSrce='$eSrce
> echo '$eDest='$eDest
>
> sedCmnd="s/$eSrce/$eDest/"
> echo '$sedCmnd='$sedCmnd
>
> # [ -d `sed -e $sedCmnd` ] && echo "Destination exists" || echo "Destination
> doesn't exist"
>
> find $srce -type d | sed -e "$sedCmnd"
>
> echo "Done."
>
> ----- End forwarded message -----
>
>
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
> _______________________________________________
> CLUE-Tech mailing list
> Post messages to: CLUE-Tech at clue.denver.co.us
> Unsubscribe or manage your options: http://clue.denver.co.us/mailman/listinfo/clue-tech
--
Edward H. Hill III, PhD
office: MIT Dept. of EAPS; Room 54-1424; 77 Massachusetts Ave.
Cambridge, MA 02139-4307
email: eh3 at mit.edu, ed at eh3.com
URL: http://web.mit.edu/eh3/
phone: 617-253-0098
fax: 617-253-4464
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://cluedenver.org/pipermail/clue-tech/attachments/20040115/70de03fe/attachment.bin
More information about the clue-tech
mailing list