Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file with multiple instances of Text_1 and Text1 and I need to replace both those strings with Text_A and TextB respectively.

Currently I'm doing two Find and Replace functions on each file one that finds Text_1 and replaces it with Text_A and the other that finds Text1 and replaces it with TextB.

Is there any way to do this all at once instead of having to run "Find and Replace" twice?

I am using Dreamweaver CS3, but I also have Notepad++, regular Notepad, OO Writer, MS Word if those will be easier. Ideally I could do this in Dreamweaver or Notepad++ but I'm open to downloading something else to get the job done. I'd prefer not to have to do any command line stuff or create a batch file (while I'm aware of it, I don't understand it really).

Edit:

In case the above description isn't clear, let me explain it this way...

I want to run Find & Replace 1 time in 1 document and I want it to do ALL of the following during that one Find & Replace instance:

  1. Find: Text_1 and Replace with: Text_A
  2. Find: Text1 and Replace with: TextB

I am not trying to do a Find and Replace across several documents.

share|improve this question
    
It might be possible using Regexp find and replace if there's a distinct pattern. Else it's not possible @matt –  Sathya Nov 15 '10 at 15:16
add comment

6 Answers

up vote 6 down vote accepted

Take a look at Sed. You can easily achieve your goal by only one command line

sed -e "s/Text_1/TextA/" -e "s/Text1/TextB/" <your_file.txt>your_file_new.txt

share|improve this answer
add comment

You're better off running Find & Replace twice, because you have two different replacements happening. However, there should be very little tradeoff in processing time. Consider the following:

Running Find & Replace once, searching term by term:

Get Term
  Does term match?  If so, replace term
Get Next Term
...

For running purposes, we'll assume it's linear and say that this runs in O(n) time.

You want to find two different terms. Running Find & Replace twice looks like:

Get Term
  Does term match?  If so, replace term
Get Next Term
...

Get Term
  Does term match?  If so, replace term
Get Next Term
...

which would take O(2x1n) time, or twice as long as searching for one term.

Searching for two terms with two replacements would theoretically look like:

Get Term
  Does first term match?  If so, replace first term
  Does second term match?  If so, replace second term
Get Next Term
...

Getting the terms does not take that much processing power, so essentially you are looking up two sets of searches for each term, giving a time of O(1x2n), running once but searching two terms.

While you would save some time not loading each term twice, you would spend more time searching each term twice, so there's little tradeoff, and since this feature would be used less often than searching one term with one replacement, application developers just assume not write that functionality.

DISCLAIMER TO PROGRAMMERS: This is a generalized example. I know it is better but I'm trying to show why that feature isn't found.

share|improve this answer
add comment

Using Notepad++, You can either

  • Open all files containing the words you want to replace and make use of Find / Replace in all open files

    enter image description here

  • Use Find / Replace in files

    enter image description here

  • Record a macro performing the find and replace options and play it back

share|improve this answer
    
That's not what I'm trying to do. I don't want to replace it on several files at once, I want to replace several strings in one file all at once. I want to be able to run one find and replace and have it search the document and replace all instances of Text_1 with Text_A and all instances of Text1 with TextB. Two seperate strings replaced with two separate values in one file. –  matt Nov 15 '10 at 14:52
    
The image-links are broken, any chance you can fix them somehow? –  Bobby Jun 10 '13 at 11:15
1  
@Bobby fixed, thanks for letting me know –  Sathya Jun 10 '13 at 11:19
add comment

Since Notepad++ 6.0 it is actually possible without scripts using the following technique:

Find: Text_1 and Replace with: Text_A

Find: Text2 and Replace with: TextB

Find: (Text_1)|(Text2)

Replace: (?1Text_A)(?2TextB)

The general syntax is:

Find: (Find1)|(Find2)|(Find3)...

Replace: (?1Replace1)(?2Replace2)(?3Replace3)...

?1 refers to the first captured phrase and so on.

I got this from the following answer: http://stackoverflow.com/a/16104946/287101

share|improve this answer
add comment

The regular expression support in Notepad++ is severely limited. Without the alternation operator, there's no hope of even coming close to what you want to do. You will need to use sed or an editor that has better regex support.

Commonly used GNU extensions to the regular expression syntax include:

  • the ? operator, meaning zero or one of a kind;
  • the | alternation operator ("foo|bar" matches either of "foo" or "bar")
  • modifiers like /g for greedy or /i for case insensitive;
  • {a,b} to denote betwen a and b tokens of a kind.
  • (pattern)+ to mach one or more matches of the same pattern

The Scitilla component, which underpins Notepad++, is strictly POSIX-compatible and does not recognise these extensions. You can consult Regular Expressions for a complete rundown and some examples

Source

See also

GNUWin32 sed for Windows

share|improve this answer
add comment

This works for all numbers (to remove all numbers from text/article)

  1. Press Ctrl+H to open the Find and Replace dialog.

  2. In the "Find what" box, type ^#

  3. Leave the "Replace with" box empty.

  4. Replace All.

share|improve this answer
1  
The OP doesn't just want the numbers removed, they wanted to replace it with a letter. –  booyaa Jun 10 '13 at 13:10
add comment

Your Answer

 
discard

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.