0

Real quick question here that i cant work out.

I have a bunch of text files across many directories. Within these dirs are text files named init.txt

In these many text files, are lots of lines starting with

Effective = 

What i need to do is replace any line that contains that string with another string, preferably in Notepad++, or UltraEdit if need be.

In Notepad++, iv found Search -> Replace in Files... which lets me specify a starting directory, but i cant get to replace the entire line with my new line.

I have never used regular expressions before (if thats the best way to do this) as iv never needed to, so any help would be very much appreciated.

Thank you for helping me out.

2 Answers2

2

For your problem, a litter regular expression may help a lot. I use regex search in Notepad++ nearly everyday, and it is really useful.

I do not want to itimidate you with some complicated regex grammar. Instead, I hope after reading my answer, you might see that the basics of regular expression is not so exotic, and it is for regular people's everyday use.

Follow these instructions:

  1. In Notepad++ press Ctrl-F, and switch to the Find in Files tab, in Serach mode part(it is on the bottom of the dialog), select Regular expression

  2. In the Find what field, what you need to input here may vary according to the specific pattern of the text you want to replace.

    If the text fragment you want to substitute always

    • Shows up at the beginning of a line,
    • There is NO LEADING WHITESPACES before the text,
    • It containes EXACTLY ONE SPCACE CHARACTER before the = character

    ^Effective = should be used as the pattern in the Find what Field.

    The ^ symbol in ^Effective = means matching begin of the line (so if Effectiv = appears in the middle of a line, it will be ignored ), and the rest is the exact words to be matched.

    However, if the above conditions is not all satisfied, e.g.

    • the text segement may containe leading whitesapces,
    • the number of withspaces between the word Effective and = symbol may vary, from one to unlimited

    Under such circumstance, you may need to use ^Effective\s+=.

    The \s+ part in ^Effective\s+= matches one to unlimited number of whitespaces(including, spaces \0x20, tabs \t, carrige-return \r, and new-line \n)

    If you want to match zero to unlimited spaces between Effective and =, you can replace \s+ to \s*

  3. In the Rplace with field, input changeLine

  4. In filters filed, select the file type you want to search

  5. Check In all sub-folders

  6. Click Replace in Files button

Archer
  • 592
  • 1
  • 4
  • 11
0

Set the search mode in Notepad++

Find: Effective = 
Replace with: changeLine 
Search Mode: Extended (\n, \t, etc)

From: https://superuser.com/questions/34451/notepad-find-and-replace-string-with-a-new-line

Community
  • 1
  • 1
RafaSashi
  • 16,483
  • 8
  • 84
  • 94