On Mon, Nov 13, 2000 at 04:32:53PM -0800, Ed Lazor wrote:
| How can I take output from an awk command and run a command on each line?
|
| For example:
|
| ls -la s* | awk '{print $9}'
|
| would create several lines of output and I'd like to do something like grep
| the lines from a file.
The canonical way is
..... | awk '{print $9}' \
| while read file
do some command using $file ...
done
I'd remark that:
ls -d s*
is better than
ls -la s* | awk '{print $9}'
because it won't break on filenames with whitespace in them, and that
for file in s*
do some command using $file ...
done
is both faster (no forking off an ls command) and better (no parsing
needed even at the line level because the results of "s*" are retrieved
directly by the shell, thus handling even very weird filenames with
newlines in them) than either. God, that's a badly constructed
sentence. Sorry.
Never forget that the shell has some handy facilities. I frequently say
echo *blah*
echo */*blah*
instead of using
find -name '*blah*' -print
when I know I have a deep directory tree and/or I know the file I'm
looking for is close to the top. Etc etc.
Cheers,
--
Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/
Usenet is essentially a HUGE group of people passing notes in class. --R. Kadel
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list