• Login
Community
  • Login

How to change text particular row and column in notepad++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 4 Posters 4.9k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    rajesh kumar
    last edited by rajesh kumar Jun 26, 2019, 3:15 PM Jun 26, 2019, 3:14 PM

    Hii…
    i have data like this…in my notepad++

    171TRM00009988000300032019060305
    50533 TRANSFERENCIAS 2202019060320190603000300030000001
    633001100119M00301100000001234545000000000000200+000000000000000 e ZAVALETA-RUIZ-CARLOS ENRIQUE 576704424233621544324211M00000051000300030000005
    !052000040301336Calle Antonio Narino 272 Urb Ceres Ate Vitarte 000000000000000000000000000000JR MIROQUESADA 441 - LIMA 011011111411000101411 000300030000005
    799D9900110011000000100030011ADDINTIONAL INFOR Z0000002 000300030000005
    80000000005000000000110011000000000000001000000000000200000000000000000 000300030000001
    90000010000000007000000000110011000000000000001000000000000200000000000000000

    i want to change row 4 and column 31&32…
    now it is 05 i need to change this 06. in my all notepad++ files.
    In all files column 31&32 with different values…Pls help me how to change text in particular row and column in all files at a time.

    Thanks.

    1 Reply Last reply Reply Quote 0
    • P
      PeterJones
      last edited by Jun 26, 2019, 3:42 PM

      @rajesh-kumar, welcome to the Notepad++ Community.

      i want to change row 4 and column 31&32…
      now it is 05 i need to change this 06. in my all notepad++ files.
      In all files column 31&32 with different values…Pls help me how to change text in particular row and column in all files at a time.

      Note that when copy/pasting your data from your post, it changes what line appears to be line 4. See the boilerplate below for instructions on how to format your post so we can actually understand. Assuming line 4 is the “word” starting with “5767”,

      171TRM00009988000300032019060305
      50533 TRANSFERENCIAS 2202019060320190603000300030000001
      633001100119M00301100000001234545000000000000200+000000000000000 e ZAVALETA-RUIZ-CARLOS ENRIQUE 
      576704424233621544324211M00000051000300030000005
      !052000040301336Calle Antonio Narino 272 Urb Ceres Ate Vitarte 000000000000000000000000000000JR MIROQUESADA 441 - LIMA 011011111411000101411 000300030000005
      799D9900110011000000100030011ADDINTIONAL INFOR Z0000002 000300030000005
      80000000005000000000110011000000000000001000000000000200000000000000000 000300030000001
      90000010000000007000000000110011000000000000001000000000000200000000000000000
      

      And assuming your description means you don’t care what’s there to start with: no matter what, on line 4, columns 31-32 should become the literal 06, it is possible, though it’s not a regex that is easy to understand.

      • FIND = (?-s)\A((?:^.*$\R+){3}^.{30})(..)((?s).*\Z)
      • REPLACE = ${1}06${3}
      • MODE = regular expression

      After verifying it works properly in one file, you can then Replace All in All Opened Documents.

      The basic gist of the regex: starting at the beginning of the buffer, match three groups of start-of-line through end-of-line including line endings, and then the first 30 characters of the 4th line, saving all that into buffer#1. Then save the 2 characters (position 31-32 of line 4) into buffer #2. Then save all remaining data from there to the end of the file into buffer#3. The replacement is contents of buffer#1, then the literal 06, then contents of buffer#3.

      If my interpretation is right, then this should work for you. However, it’s likely that you haven’t actually given us enough information to truly craft the regex. See the advice below for improving your question. Note: if it doesn’t work right away, you’ll have to explain what went wrong, and give an attempt to modify the regex. If you don’t follow formatting advice and show effort (ie, that you’ve read some of what’s below), it will be harder for you to get further help in this forum.

      -----
      FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before. Here is some helpful information for finding out more about regular expressions, and for formatting posts in this forum (especially quoting data) so that we can fully understand what you’re trying to ask:

      This forum is formatted using Markdown, with a help link buried on the little grey ? in the COMPOSE window/pane when writing your post. For more about how to use Markdown in this forum, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes ("") to curly “smart” quotes (“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is c:\folder\*.txt, it will show up as c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it.

      If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

      Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.

      1 Reply Last reply Reply Quote 2
      • G
        guy038
        last edited by guy038 Jun 26, 2019, 7:12 PM Jun 26, 2019, 6:39 PM

        Hello, @rajesh-kumar, @PeterJones, @Terry-R and All,

        Note, @rajesh-kumar, that the \A regex assertion, matching the zero-length location at the very beginning of current file, is bugged with current version of the regex engine !

        So, this explains why Peter, choose to search for all file contents, splitting it in 3 parts :

        • The part of file, from the very beginning till the location 30, of the 4th line of current file

        • The two characters at locations 31 and 32 of the 4th line

        • The part, from location 33 of the 4th line till the very end of the current file

        Indeed, if we use, instead, the regex (?-s)\A(.+\R){3}.{30}\K.{2}, you should see that the regex wrongly searches the two characters, at locations 31 and 32, every 4 lines of current file :-((


        Normally, this regex should find, exclusively, the two chars, at locations 31 and 32 of the 4th of current file scanned !

        Luckily, thanks to Terry’s inspiration, who found an elegant work-around to mimic the \A assertion. His solution is not perfect but it’s more closed to the true definition of the \A assertion ;-)). Refer to these posts :

        https://notepad-plus-plus.org/community/topic/16104/how-to-find-and-highlight-a-specific-occurance-of-a-symbol/9

        https://notepad-plus-plus.org/community/topic/16104/how-to-find-and-highlight-a-specific-occurance-of-a-symbol/10

        and my reply :

        https://notepad-plus-plus.org/community/topic/16104/how-to-find-and-highlight-a-specific-occurance-of-a-symbol/12

        Using Terry’s work-around means that you must replace any \A assertion with the regex (?<!\n|\r)^. This regex searches for a beginning of line ^, but ONLY IF it is not preceded with, either, the \r char OR the \n char !

        So, the previous regex must be changed into (?-s)(?<!\n|\r)^(.+\R){3}.{30}\K.{2}


        Now, here is, below, a generic regex S/R :

        SEARCH (?-s)(?<!\n|\r)^(?:.+\R){W-1}.{X-1}\K.{Y}

        REPLACE  Z

        which replaces the Y characters, beginning at location X, of the line W, of all the files scanned, with the string Z

        Regarding your case, this leads to the effective regex :

        SEARCH (?-is)(?<!\n|\r)^(?:.+\R){3}.{30}\K.{2}

        REPLACE 06

        So, assuming that all your files are in a specific folder :

        • Open the Find in Files dialog ( Ctrl + Shift + F )

        • Type in the Search and Replace zones, as noticed above

        • Possibly, check the Match case option, if you looks after letters

        • Select the Regular expression search mode

        • Click on the Replace in Files button

        • Confirm the Are you sure? dialog

        Et voilà !

        Remarks :

        • I advice to test it, first, with 1 or few files, using the Replace dialog Ctrl + H

        • However, due to the \K structure, you’ll have to click, exclusively, on the Replace All button


        Notes :

        • First, the in-line modifier (?-is) :

          • Forces the regex engine to consider that any dot . represents a single standard character only ( not EOL characters )

          • Forces the search to be processed, in a non-insensitive way

        • Then, the part (?<!\n|\r)^ looks for a beginning of line, not preceded with any EOL char.

        • Now, the part (?:.+\R){3} grabs the first three lines of current file, with their EOL chars, in a non-capturing group

        • So, the part .{30} matches the first 30 characters of the 4th line

        • The \K syntax resets the regex engine search and position !

        • So that, it searches, now, for the simple regex .{2}, i.e. the two characters, at locations 31 and 32 !

        • Finally these two characters are replaced with the string 06

        Best Regards,

        guy038

        P.S. :

        A last example :

        Let’s suppose that you would like to replace, in a bunch of files, 5 characters, followed with the string FALSE, with this exact case, beginning at location 50 of the 12th line, with the string TRUE

        Then, from the generic regex above, it comes :

        SEARCH (?-is)(?<!\n|\r)^(?:.+\R){11}.{49}\K.{5}FALSE

        REPLACE TRUE

        Of course, I assumed that the 12th line, of each file, contains, at least, 59 chars !

        R Shubhada WavaleS 2 Replies Last reply Jun 27, 2019, 3:01 PM Reply Quote 2
        • R
          rajesh kumar @guy038
          last edited by Jun 27, 2019, 3:01 PM

          Hii…@guy038

          Thank u so much its works…thanks

          1 Reply Last reply Reply Quote 0
          • Shubhada WavaleS
            Shubhada Wavale @guy038
            last edited by Apr 10, 2024, 11:57 AM

            @guy038

            Hi , I tried this solution it works.
            However if I want to replace on all lines which are nearly 40k instead of only single line 4 , what will be the regex ???

            1 Reply Last reply Reply Quote 0
            • G
              guy038
              last edited by guy038 Apr 10, 2024, 1:53 PM Apr 10, 2024, 1:46 PM

              Hello, @shubhada-wavale and All,

              In this case, the regex S/R is greatly simplified !

              The generic regex S/R to use becomes :

              • SEARCH (?-is)^.{O}\K.{N}

              • REPLACE R

              Where :

              • O ( for OFFSET ) represents the leading number of characters, of each line, to discard from the search

              • N represents the number of characters to replace, in each line

              • R represents the replacement expression to replace, in each line, the N characters, found after the first O characters

              Remarks :

              • You must check the Wrap around option and select the Regular expression search mode

              • Note that the replacement R may be an empty string if you want to delete the N characters of each line

              • If the replacement part R contains parentheses, you must escape each of them with an antislash char


              For instance, given the text in the first post, above :

              <----------25-----------><-5->
              171TRM00009988000300032019060305
              50533 TRANSFERENCIAS 2202019060320190603000300030000001
              633001100119M00301100000001234545000000000000200+000000000000000 e ZAVALETA-RUIZ-CARLOS ENRIQUE 
              576704424233621544324211M00000051000300030000005
              !052000040301336Calle Antonio Narino 272 Urb Ceres Ate Vitarte 000000000000000000000000000000JR MIROQUESADA 441 - LIMA 011011111411000101411 000300030000005
              799D9900110011000000100030011ADDINTIONAL INFOR Z0000002 000300030000005
              80000000005000000000110011000000000000001000000000000200000000000000000 000300030000001
              90000010000000007000000000110011000000000000001000000000000200000000000000000~~~
              

              Then, the regex S/R :

              • SEARCH (?-is)^.{25}\K.{5}

              • REPLACE | This is a test |

              would change that text as below :

              <----------25----------->| This is a test |
              171TRM0000998800030003201| This is a test |05
              50533 TRANSFERENCIAS 2202| This is a test |0320190603000300030000001
              633001100119M003011000000| This is a test |545000000000000200+000000000000000 e ZAVALETA-RUIZ-CARLOS ENRIQUE 
              576704424233621544324211M| This is a test |051000300030000005
              !052000040301336Calle Ant| This is a test |Narino 272 Urb Ceres Ate Vitarte 000000000000000000000000000000JR MIROQUESADA 441 - LIMA 011011111411000101411 000300030000005
              799D990011001100000010003| This is a test |DDINTIONAL INFOR Z0000002 000300030000005
              8000000000500000000011001| This is a test |00000000001000000000000200000000000000000 000300030000001
              9000001000000000700000000| This is a test |11000000000000001000000000000200000000000000000~~~
              

              Best Regards,

              guy038

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors