On Dec 9, 2010, at 3:21 PM, Paul Graydon wrote:
> On 12/09/2010 12:07 PM, Randal L. Schwartz wrote:
>>>>>>> "Jan" == Jan L Peterson<[email protected]> writes:
>> Jan> (eval `ls -1 *.meta | while read m; do f=\`grep "^Filter:" $m | awk
>> '{print $2; exit}'\`; echo -n "./$f -r \`basename $m .meta\` |"; done | sed
>> -e "s/|$//"`)< input> output
>>
>> Jan> which gets rid of the multiple "cut" commands, "head", one of the
>> Jan> nested loops, and both gratuitous uses of "cat".
>>
>> But still leaves the evil of "ls *wild*card*", which is almost always
>> wrong, unless what you're trying to do is get the contents of many
>> subdirectories whose name matches a pattern.
>>
> If you're going to do such a thing I would have thought find would have
> been the better command to use, using its exec flag to make sure file
> names with spaces or other odd characters get handled correctly.
>
> I was always taught that pushing output from ls to another command is
> wrong, wrong, wrong, and the few times I've done it in a fit of
> stupidity has always backfired on me!
Randal and Paul (sorry if you get this twice, Paul, the first reply went out
from the wrong address),
I was never taught that this was wrong. I've often piped the output of ls into
a while loop when I've needed to do something along these lines. Please
educate me as to how "ls -1 *.meta" is wrong in this case. I would think find
is especially wrong because it descends directories.
Also, can you suggest any alternate ways to get a list of files ending in .meta
that doesn't use a wildcard?
In any case, the choice of command came directly from the original poster's
example. I would hope he (waves at David) knows what the structure of his
directory is and what files are expected to be present or not present.
-jan-
--
Jan L. Peterson
http://www.peterson-tech.com/~jlp/
_______________________________________________
Discuss mailing list
[email protected]
https://lists.lopsa.org/cgi-bin/mailman/listinfo/discuss
This list provided by the League of Professional System Administrators
http://lopsa.org/