As it reads in the title above, I had to do the same edit in fourteen files.
Attempting this by use of the GUI (Windows, buttons and mouse clicks!) would be a TEDIOUS task, prone to result in mistakes.

Here is how I did it – with the use of bash contained in cygwin.

Below you see five lines that I typed at the bash shell prompt. I’ll explain them below, but first a note:
The prepended numbers and periods are there to allow me reference to each line, don’t type them if you try this.

  1. cd “LocationOfFiles/”
  2. for singlefile in *.xml ; do
  3.   if [ ! -s “$singlefile.old” ] ;then mv “$singlefile” “$singlefile.old” ; fi
  4.   sed -re ‘s/OldText/NewText/g’ <“$singlefile.old” >”$singlefile” ;
  5. done

The first line (1.) simply moves attention to the folder where the files resides, by use of the “change dir” command; “cd”.  “LocationOfFiles/” of course should be something that makes sens for your attempt, e.g. “C:/Documents and Settings/Username” where you replace Username with the actual login name you have (an existing folder!).

The second line has the word “for” first, the command to eachieve repetitions. The next word, “singlefile”, is a name that will act as a container – this name could read almost anything,  just avoid the reserved words in bash. “in” is one of those reserved words, telling “for” that we want to repeat once for each item that follows. *.xml is a file pattern that will be replaced by a list of filenames that match it. The names of fourteen files with a name ending with .xml in my case, the “;” marks the end of the list (and command). The last reserved word is “do” which is the “left parenthese” for the commands to repeat, “done” on line five is the right hand parenthese.

Line three contains a conditional execution of a mv command; “!” should be read “not”, “-s” indicates “that the the file named should be checked creating a return of “TRUE” if it exists and contains data. The square brackets with space characters on both sides as written here are the “box” for the test. If the test is NOT TRUE (which by definition of “-s” means that the file doesn’t exist or contains no data) then the original file named by the contents in “$singlefile” will be moved (by “mv” command) to a file with “.old” appended to the original name. “fi” marks the end of the conditional execution.

Line four; uses “sed” (stream editor) with the flags “r” and “e” to substitute (the first s after the single quote is a sed-command) “OldText” into “NewText” in the data that sed gets fed from “$singlefile.old”.
As sed looks on one line at a time, the substitution is to be applied globally, i.e. for all occasions of “OldText”, which is why there is a “g” after the last slash. 

As you can see from the above each and every little character here has meaning. You have to be cautious to not misspell or omit something, but as you are done typing and hit enter – the commands get executed in a few seconds and does all the editing, exactly as you told.

Good luck.

Advertisements