[lug] Displaying a list of files

Tkil tkil at scrye.com
Thu Dec 12 12:58:04 MST 2002


>>>>> "Jeff" == Jeff Schroeder <jeff at neobox.net> writes:

Jeff> I have a shell script that collects a list of files with
Jeff> potential problems in them, and displays the list to the user as
Jeff> part of an installation process.  I'm storing the list in a
Jeff> shell variable, like so:

Jeff> list=`find -type f -exec grep -li "problem code" {} \;`

Jeff> but when I try to echo it to the user I get a space-delimited list:

Jeff> path/file1.php path/file2.php path/file3.php

Jeff> What I'd prefer (for readability) is a newline-delimited list:

Jeff> path/file1.php
Jeff> path/file2.php
Jeff> path/file3.php

Try using xargs instead:

  find . -type f -print0 | xargs -0 grep -li 'problem code'

This should also be somewhat more efficient than using the "-exec"
flag to 'find', since this only launches one grep process for multiple
files, instead of one grep per file.

The really fun part is that you can cascade the output from that into
another xargs, if you like.  :)

t.



More information about the LUG mailing list