[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep question



On Sun, 2004-12-05 at 18:06, Harold Crouch wrote:
> What is the correct Bash command to search for all occurrences
> of 'this_string' in all files in a folder and its sub-folders?

You could use a for|find loop or a find|xargs command.

E.g.,
  for file in `find . -mount`; do grep -i (string) "${file}"; done
Or
  find . -mount | xargs grep -i (string)

You could also get fancy and test for a "regular file" with:
  for file in `find . -mount`; do
    [ -f "${file}" ] && grep -i (string) "${file}";
  done

Note there may be issues with for loops if paths have spaces in them. 
You can redefine the LFS variable to accommodate this.  Some versions of
bash allow you to put quotes around the backticks, while others don't
work if you do that.

I found the Advanced Bash Scripting Guide doesn't note that very well.  
Some bash versions differ on how a double-quoted backtick returns
parameters.  Hence why I sometimes use tcsh instead of bash --
especially if I'm writing a script for different systems.

-- 
Bryan J. Smith                                    b.j.smith@ieee.org 
-------------------------------------------------------------------- 
Subtotal Cost of Ownership (SCO) for Windows being less than Linux
Total Cost of Ownership (TCO) assumes experts for the former, costly
retraining for the latter, omitted "software assurance" costs in 
compatible desktop OS/apps for the former, no free/legacy reuse for
latter, and no basic security, patch or downtime comparison at all.



-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.