Community
    • 登入

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

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    7 貼文 3 Posters 2.9k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Denis StaD
      Denis Sta
      最後由 編輯

      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.

      Scott SumnerS 1 條回覆 最後回覆 回覆 引用 0
      • Scott SumnerS
        Scott Sumner @Denis Sta
        最後由 編輯

        @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 條回覆 最後回覆 回覆 引用 1
        • Contafisc EmpresarialC
          Contafisc Empresarial
          最後由 編輯

          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 條回覆 最後回覆 回覆 引用 1
          • Contafisc EmpresarialC
            Contafisc Empresarial
            最後由 編輯

            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 條回覆 最後回覆 回覆 引用 0
            • Scott SumnerS
              Scott Sumner
              最後由 Scott Sumner 編輯

              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 條回覆 最後回覆 回覆 引用 2
              • Contafisc EmpresarialC
                Contafisc Empresarial
                最後由 編輯

                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)…

                Scott SumnerS 1 條回覆 最後回覆 回覆 引用 0
                • Scott SumnerS
                  Scott Sumner @Contafisc Empresarial
                  最後由 編輯

                  @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 條回覆 最後回覆 回覆 引用 1
                  • 第一個貼文
                    最後的貼文
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors