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