kyle_in_taiwan
asked on
Almost-as-easy: How to test for the existence of a filename within a list.
Almost as easy, but still very easy (i think) --
This is the same example i gave from "Easy-Peasy", but there's an aspect that i still need answered:
: > FileList
find ./ -name XXX.YYY |
while read "b"
do
c=`dirname "$b"`
d=`sed -n '/"$c"/p' FileList`
if [ "$d" = "$c" ]
then
continue
else
echo "$c" >> List
fi
done
What i'm interested in is taking that sed command, that defines the "d", and then testing to see if it exists within a given file (or stream). I then want to build case- or if-loops off of that.
How do i do it? I was under the impression here that sed'd be printing any line that already had the $c pattern in it, and then the script would continue; whereas if the line didn't exist within the FileList then it'd get echoed into the list and continue.
Script didn't work out that way, though. So i also tried this:
if [ "$d" = "" ]
then
echo "$c" >> List
else
continue
fi
So i'm stymied; how do i work out this "test" command?
This is the same example i gave from "Easy-Peasy", but there's an aspect that i still need answered:
: > FileList
find ./ -name XXX.YYY |
while read "b"
do
c=`dirname "$b"`
d=`sed -n '/"$c"/p' FileList`
if [ "$d" = "$c" ]
then
continue
else
echo "$c" >> List
fi
done
What i'm interested in is taking that sed command, that defines the "d", and then testing to see if it exists within a given file (or stream). I then want to build case- or if-loops off of that.
How do i do it? I was under the impression here that sed'd be printing any line that already had the $c pattern in it, and then the script would continue; whereas if the line didn't exist within the FileList then it'd get echoed into the list and continue.
Script didn't work out that way, though. So i also tried this:
if [ "$d" = "" ]
then
echo "$c" >> List
else
continue
fi
So i'm stymied; how do i work out this "test" command?
> d=`sed -n '/"$c"/p' FileList`
i guess you want to write
d=`sed -n /"$c"/p FileList`
i guess you want to write
d=`sed -n /"$c"/p FileList`
ASKER
Hm. I tried that, and got this error (for each line in the first set of directories):
sed: -e expression #1, char 5: extra characters after command
And that then turned to this (which has a couple of characters truncated from the beginning):
sed: can't find label for jump to `QAnnReturn/p'
sed: -e expression #1, char 5: extra characters after command
And that then turned to this (which has a couple of characters truncated from the beginning):
sed: can't find label for jump to `QAnnReturn/p'
ASKER
My understanding is that the regex portions of sed scripts need to be escaped with single quotes so they can be properly interpreted by the shell; but perhaps there are different ways of finagling the shell profile?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> sed: -e expression #1, char 5: extra characters after command
sounds like your $c contains spaces or other meta characters, try
d=`sed -n '/'"$c"'/p' FileList`
sounds like your $c contains spaces or other meta characters, try
d=`sed -n '/'"$c"'/p' FileList`
ASKER
Heh.
Yeah, i already said on another thread that this is a learning exercise; i'm *very* new to playing around with this stuff.
Thanks for the heads-up on the find command; you're right, and i'm slapping myself in the head for not thinking about it before (never having used the -exec flag before, it's a light slap).
Thanks both. I'll get back to this later this evening.
Yeah, i already said on another thread that this is a learning exercise; i'm *very* new to playing around with this stuff.
Thanks for the heads-up on the find command; you're right, and i'm slapping myself in the head for not thinking about it before (never having used the -exec flag before, it's a light slap).
Thanks both. I'll get back to this later this evening.
ASKER