• Login
Community
  • Login

Getdata from specific positions (only if position x is not "0") and replace another positions with it

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
7 Posts 3 Posters 2.8k 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.
  • D
    Denis Sta
    last edited by Jun 22, 2017, 1:59 AM

    HI all, i’m kinda newbie at using notepad++, finding it’s awesome uses and functions…
    I’m trying to edit some files, here’s what i need to accomplish:
    I need to copy the info from positions 117 to 121 (5 numbers, fixed position, thousands of lines) and replace the info on position 120 to 124 with the info i got from 117 to 121 (replacing 117 to 119 with zeroes), but i only would do that on lines that the caracter on position 119 is diferent from 0, otherwise no need need to be done on that line.
    here’s a example of a line that would need to changed (2 on 119° position. I assume site would change format of line so it won’t show as in the archive, but it’s the first 126 caracteres -from a 400 fixed position line, i believe should be enough to explain my need)
    1 A000RY029052 162006335 232601170024104001
    -so the line would turn into this (the line should stay with 400 positions):
    1 A000RY029052 162006335 232601170000024101
    -and here’s a example of a line that shouldn’t be affected by (had 0 on position 119 and should stay as is)
    1 A018AC000002 172017097 122601170000064401

    Any help is greatly appreciated, as i’m not getting luck in figuring it out until now.
    (As a plus, if there’s a way to execute this function leaving the first and last line out, that would be excelent).

    Thx a lot in advance for any help.

    S 1 Reply Last reply Jun 22, 2017, 12:57 PM Reply Quote 0
    • S
      Scott Sumner @Denis Sta
      last edited by Jun 22, 2017, 12:57 PM

      @Denis-Sta

      Not too hard; I’ll leave the bonus part to someone else, though. :-D

      Find-what box: ^(.{116})(..[^0]..).{3}
      Replace-with box: \1000\2
      Search mode: Regular expression

      How it works:

      Starting at the beginning of each line, remember 116 characters as group-1, then remember the next 5 characters where the middle digit (or col 119 digit) is not zero as group-2, then grab the next 3 characters (don’t remember those 3 as they will not be used in the replace part). Now that we have these things remembered, replace the entire matched part of the line (which is the first 124 characters) with the memorized group-1 data, followed by three zeroes, followed by the remembered group-2 data.

      1 Reply Last reply Reply Quote 1
      • C
        Contafisc Empresarial
        last edited by Jun 22, 2017, 2:12 PM

        Great, thx a lot, i was doing something like that, but was missing some key parts, that would solve my problem, thx again.
        Il’l take a look around, maybe i can contribute aswering some other easier questions.
        Regards.

        1 Reply Last reply Reply Quote 1
        • C
          Contafisc Empresarial
          last edited by Jun 22, 2017, 5:18 PM

          btw this worked on multiple archives, without need to filter the lines (as the first and last lines didn’t had any “0” on the 119° position they aren’t changed at all.
          Thx again.

          1 Reply Last reply Reply Quote 0
          • S
            Scott Sumner
            last edited by Scott Sumner Jun 22, 2017, 5:46 PM Jun 22, 2017, 5:44 PM

            I’m glad it was helpful to you.

            In the future for postings that are helpful, instead of posting a “thanks”, simply press the caret-like “UP-vote” button (see picture below) on that posting.

            This:

            • Will let me know that you found value in my posting; effectively a “thanks” (I get a notification)
            • Won’t waste the bandwidth of others that read the Community with a valueless (to them) “thanks” posting they have to read [they won’ t see new things in their “Inbox” for upvotes]
            • Will increase my “reputation”; whatever the value is in that… “repu-coins”? :-D

            1 Reply Last reply Reply Quote 2
            • C
              Contafisc Empresarial
              last edited by Jun 27, 2017, 3:28 PM

              Great, i will do that.
              Another question, how would i add a parameter like “or” on 2nd group?
              like: i want to replace if 119° “or” 120° caracter are diferent from zero or space (i could add the space no problem, but as i add 2 parameters it only would replace when both are valid)…

              S 1 Reply Last reply Jun 27, 2017, 3:46 PM Reply Quote 0
              • S
                Scott Sumner @Contafisc Empresarial
                last edited by Jun 27, 2017, 3:46 PM

                @Contafisc-Empresarial

                Unless I am misunderstanding what you are wanting to do (very possible!), I’d say that changing [^0]. to [^\s0]{2} does what you need. It means: for the next two positions, match as long as both positions are not some combination of:

                • whitespace (the \s)
                • zero (the 0)
                1 Reply Last reply Reply Quote 1
                4 out of 7
                • First post
                  4/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors