Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for an automated solution than can search if a specified text string is on a line (may not be an exact match - just as long as the specified text string is contained in the line) on a group of text files and will remove the whole line (or lines) where the text string is/are found and replace it with a text string I specify. I am using Windows 7.

Reason for this: I edit AI files for an old strategy game (Total Annihilation). The AI files are basically text files, with a different AI file per map type. If I would like to make a particular edit the same in all the AI files, I would have to edit a lot of text files.

share|improve this question
up vote 2 down vote accepted

Notepad++, (also available as a portable app), will do a search and replace on files in the current directory and all subdirectories using regular expressions, in the search menu go to replace and then click on the "find in files" tab select the "regular expression" search mode type "^.*your_string.*$" in the search field and "your_new_string" in the "replace with" field.

better test it first.

share|improve this answer

You can use sed in Windows. One source is GnuWin32. A typical command might look like this:

sed '/search pattern/s/^.*$/This is the new text/' file*.txt

which says "on every line in every file (named file[something].txt) that includes the text "search pattern", replace the whole line with "This is the new text".

More complex operations can be performed using regular expressions and other commands.

share|improve this answer

AutoIt can do this easily. You can look at this post for an example I wrote that does similar to what you need. The source I provided would only need minor tweaking to accommodate your needs, and could be made to do all the files at once.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.