Search And Replace in multiple lines.

Carlos
2011-09-06
2012-11-13
  • Carlos
    Carlos
    2011-09-06

    Hi!

    I have a little problem, i need to find a word on 1 line and when find, replace som caracters on the other line below:

    Ex:
    613196 04013029000CREME DE LEITE 300GR PCT  UN UN 000000000000000P 00 00000000  4110                 
    620000000600000  000000001188000000000000S0605405VENDA A VISTA 00000000000000000                   0000000000

    when i have '4110' in line initiate by '61', i need '00000132013200000' in line '62' like this:

    613196 04013029000CREME DE LEITE 300GR PCT  UN UN 000000000000000P 00 00000000  4110                 
    620000000600000  000000001188000000000000S0605405VENDA A VISTA 00000132013200000                   0000000000

    but the rest of the vales are the same.

    can someone help me?

     
  • Carlos
    Carlos
    2011-09-08

    someone please? :D

     
  • Fool4UAnyway
    Fool4UAnyway
    2011-09-08

    You could use Digital Volcano's Text Crawler to perform a multiline regular expression replacement.
    But it may be hard for you to figure out just how to do that. This would involve counting character( positions).

    You may use the Maco (Record and Playback) feature in Notepad++.
    It looks like your file is fixed positioned: every line contains the same kind of data at the same fixed positions, a part of data on always has the same length for all lines.

    First, copy the text 00000132013200000 to the clipboard. You will paste this on the lines to be changed.

    Next, open the Find dialog and check the Regular Expression Mode radio button.

    Type the following text in the Find field:
    ^61

    Press the Find button and check that this finds a line that starts with the text 61.
    Close the Find dialog.

    Press Ctrl+Home to move to the top of the document.

    Start the Macro recorder.

    Press F3 to find the next ^61 occurrence. This could be at the very first line for the first search.
    Press the CursorDown key.
    Press the End key.
    Press Ctrl+CursorLeft keys at the same time.
    Press Ctrl+CursorLeft keys at the same once more.
    Press Ctrl+Shift+Cursor Right keys at the same time.
    Press Ctrl+V to overwrite the selected 00000000000000000 with the desired 00000132013200000.

    Stop the Macro Recorder.

    Play back the Macro multiple times and choose the option "until the end of file/document".

     
  • Carlos
    Carlos
    2011-09-09

    ty for help :)

    but i have more 2 problems, not all lines that starts with '61' are equal i have lines like that:
    613196 04013029000CREME DE LEITE 300GR PCT  UN UN 000000000000000P 00 00000000  0                 

    sometime is ´4110´ then the next line need to be 00000132013200000, and sometimes is 0 then, the next line need to be 00000000000000000.

    Then i use this expression ^61.*4110.*$

    works, but the file have 45000 lines… and the program breaks when i execute the macro until the end of file…

    more some suggestion?

    thanks

     
  • Fool4UAnyway
    Fool4UAnyway
    2011-09-09

    You could use the following expression, as 4110 seems to be the last text on the line, although in the text above there are some space characters following 4110:

    ^61.*4110$

    or, if there may be any whitespace (space or tab characters):

    ^61.*4110\s*$

    I'm not sure what the maximum number you can enter for repeats is.
    You may try 5 steps of 10000, for example.

    Another way to do the replace operation is using Text Crawler.
    It supports multiline regular expressions.

    www.digitalvolcano.co.uk/content/textcrawler

    You can test the working in the Regular Expression Tester dialog on a few lines first.

    It looks like the words in the file are separated by single space characters. If not, you may replace the space characters below by + (or " *" by "*"), where \t represents a tab character.

    Find:
    (\r\n61.*4110 *\r\n62.*) 0+ ( *0+ *)

    Replace by:
    $1 00000132013200000 $2

    You might want to specify the actual numbers of 0's for the 0 strings.

    Find:
    (\r\n61.*4110 *\r\n62.*) 0{17} ( *0{10})

    You could do the same for the variable text part, if it always has the same length, that is, if all your text/number columns are on fixed positions.

    Find:
    (\r\n61.{78}4110 *\r\n62.{60}) 0{17} ( *0{10})

     
  • THEVENOT Guy
    THEVENOT Guy
    2012-10-21

    Hello carlosgk,

    I've been registrated on Notepad Forums, on 08-15-12 only, so I assume that you
      could fully manage your problem, since your post !

    But, with the new PCRE regular expressions, from Notepad++ 6.0 Unicode and above,
      the simpliest solution seems to be :

     
    FIND            :    ^(61.*4110.*\R.*)0{17}

    REPLACE  :    ${1}00000132013200000
     

    Of course, you must select the radio button 'Regular expressions'
     

    Some explanations :

      \R stands for the New Line character(s)  ( = \r\n if WINDOWS file, = \n if UNIX file and =\r if MAC file )

      ${1} means all the string between the parentheses ( exactly as \1, but without the \100000132013200000 ambiguity ! )
           and stands for ALL the characters between '61' at the BEGINNING of a line and the SPACE BEFORE the
           17-digits number, in the NEXT line
     
      0{17} stands for a string of 17 CONSECUTIVE zeros

     
    I've made a TUTORIAL, about the PCRE Regular Expressions ( Perl Common Regular Expressions ),
      used in Notepad++, from the 6.0 version.

    As I'm French, all this manual is written in French. but you can find out some tricks or
      explanations in all the lists and examples, all along this tutorial.

    Christian Cuvier ( cchris ), a very well-known contributer, allowed me to put my tutorial
      on his personnel site.

    So, you can download this TUTORIAL, in 3 versions, (.txt .pdf .html), at the address below :

           http://oedoc.free.fr/Regex/TutorielRegex.zip

    I hope it'll be useful to you

    Cheers !

    guy038

    P.S. You can find some documentation, about the new PRCE Regular Expressions, used by N++, at the
           two adresses below

         http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

         http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

         The FIRST one concerns the syntax of regular expressions in the SEARCH part

         The SECOND one concerns the syntax of regular expressions in the REPLACEMENT part