home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / question / 13613 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  2.1 KB

  1. Xref: sparky comp.unix.questions:13613 comp.unix.misc:4252
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!rutgers!fdurt1.fdu.edu!wisdom.bubble.org!sugra!ken
  3. From: ken@sugra.uucp (Kenneth Ng)
  4. Newsgroups: comp.unix.questions,comp.unix.misc
  5. Subject: Re: Unattended execution
  6. Message-ID: <1992Nov19.033926.11705@sugra.uucp>
  7. Date: 19 Nov 92 03:39:26 GMT
  8. References: <Bxprsz.EnL@andy.bgsu.edu: <BxsH17.Cuu@magpie.nycenet.edu>
  9. Organization: Private Computer, Totowa, NJ
  10. Lines: 39
  11.  
  12. In article <BxsH17.Cuu@magpie.nycenet.edu: manes@magpie.nycenet.edu (Steve Manes) writes:
  13. :Bob Lee (rlee@bgsu.edu) wrote:
  14. :: There is a task I want to perform, it includes recursively searching over
  15. :: 200 directories and over 1000 files for an occurance of a text string in
  16. :: any of the files. As you probably guessed, this task takes quite a while
  17. :: and I want to do it for more than one text string.
  18. :See at(C).
  19.  
  20. At on my machine will schedule a task to run at a certain time.  I had a real
  21. dangerous script that looked for printable files, greped out a string, and
  22. than ran sed to replace all occurrance of that string with a new string.
  23. Real dangerous if some novice decides to change all 'a' to 'b' :-).  The
  24. relevant part of the code is:
  25.  
  26. gfind . -type f -print | xargs printable | xargs grep "stuff" \
  27. | awk -F: '{ print $1 }' | sort | uniq
  28.  
  29. Now, what this does in english :-).  gfind finds all files I want to deal
  30. with, modify to your hearts content.  'printable' was a local function to
  31. determine what files one wanted to look at (it ignored object code, data
  32. bases, etc), the grep searches for the string I want, the awk yanks out
  33. the file name, the 'sort | uniq' gives me a unique list of the files that
  34. contain the string.  And for the curious, this is the program I piped the
  35. output into to change all the strings (from memory):
  36.  
  37. #! /bin/csh
  38. foreach file ($*)
  39.    cp ${file} ${file}.save
  40.    sed 's/old/new/g' < ${file}.save > ${file}
  41.    end
  42.  
  43. Be warned, this routine can be VERY dangerous if you are not real careful
  44. about what you want to change.
  45.  
  46.  
  47. -- 
  48. Kenneth Ng
  49. Please reply to ken@eies2.njit.edu for now.
  50. Apple and AT&T lawsuits: Just say NO!
  51.