Loading ...
Sorry, an error occurred while loading the content.
 

Re: [jasspa] Search and Replace in all files

Expand Messages
  • Thomas Hundt
    The really efficient way involves Perl, and no Jasspa at all. find calling Perl (this is all one line), replace Galations with Galatians : find ./ -type f
    Message 1 of 4 , Feb 10, 2004
      The really efficient way involves Perl, and no Jasspa at all.

      'find' calling Perl (this is all one line), replace "Galations" with
      "Galatians":
      find ./ -type f -name '*.htm*' -exec perl -pi -e
      's/Galations/Galatians/g' {} \;

      Pure Perl solution, search and replace <strong> with <b> in all *.html
      files (saves original files as *.html.bak):
      perl -pi.bak -e 's/strong>/b>/gi;' *.html

      Perl runs well under Windows, so you could use it even if you don't have
      'find' nor Cygwin installed.

      -Th



      Steven Phillips wrote:

      > There are two other solutions to solving this problem and which one to use
      > depends on the scale of the replacing:
      >
      > 1) For a small number of replacements I tend to use the rgrep (recursive grep)
      > command to find all the strings to be replaced in all the directory-tree. This
      > command is available on windows as long as you make cygwin's 'find' first in
      > the path (see help page). I then create a simple key-board macro which
      > typically uses the get-next-line and '-1 replace-string ...' commands to do
      > the actual replacement. This is a very quick and easy solution.
      >
      > 2) I once decided that in a large library (thousands of lines of code split
      > across many directories) that its definition and use of int32 was not a good
      > idea (caused compile error on AIX) so should be changed to xxInt, float32 ->
      > xxFloat, same for int8, float64 and then theres all the functions that have
      > types in their name etc etc. I ended up with a list of 100+ changes to be
      > made - rather a large headache.
      >
      > It was for this reason I created the replace-all-pair command. I started by
      > concentrating on the first compiled directory and created a list of
      > replacement pairs which up-graded that directory AND made sure that that
      > directory still worked/compiled. I then moved onto the next, used
      > replace-all-pair on the existing list and then added to the list any other
      > changes need for that directory. And then I moved onto the next and the next.
      >
      > The process did not take long and once complete I had a complete list of all
      > the changes made in a form that meant I could easily upgrade all programs that
      > used the library (using replace-all-pair obviously). Again this approach is
      > also available on windows and only requires access to a reasonable grep
      > command, see help page on the command. One further tip, when adding to the
      > replacement list I used the Edit -> Narrow To feature to exclude replacement
      > pairs that had already been applied to avoid re-applying them as this could
      > lead to unwanted side effects. If you use this approach please backup your
      > files first as changes tend to be permanent!
      >
      > Steve
      >
      >
      >>Subject: [jasspa] Search and Replace in all files
      >>From: Jon Green <jon@...>
      >>Date: Tuesday, February 10, 2004, 7:59:09 PM
      >>To: jasspa@yahoogroups.com
      >>salmankhilji wrote:
      >>
      >>>I would like to replace a text string with another inside the entire
      >>>directory. ME should recursse into all sub-directories and find all
      >>>*.[hHcC]* files and carry out the replacement.
      >>>
      >>>There is the command replace-all-string, but I don't want to manually
      >>>enter a list of all the files in which the replacement should occur.
      >>>
      >>>I could use the find command but then I need a way to carry out the
      >>>repalcement using the command line. I tried something like this on
      >>>one file but it didn't work.
      >>>
      >>>me "@replace-all-string" ContentStream Stream opCurveY.cpp
      >>>
      >>>Can someone please help me
      >>>
      >>>Salman
      >>>
      >>>
      >
      >
      >>Well running on UNIX then you can do the following
      >
      >
      >>(query-)replace-all-string
      >>Replace all: AAA
      >>Replace [AAA] with: BBB
      >>In Files: *.cpp */*.cpp */*/*.cpp */*/*/*.cpp
      >
      >
      >>Add as many stars as you need levels.
      >
      >
      >>If you are running on Windows then this will depend what
      >>kind of grep you have and how it behaves with '*'s
      >
      >
      >>Must admit would be nicer with find, but does the job.
      >
      >
      >>Jon.


      --
      Thomas Hundt
    Your message has been successfully submitted and would be delivered to recipients shortly.