• Login
Community
  • Login

Need help with replacing/editing lines!

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
8 Posts 3 Posters 2.0k 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.
  • M
    Moking C
    last edited by Jan 26, 2022, 7:42 AM

    Hello everyone, desperately need some help with replacing lines.
    My work requires me to occasionally use Notepad++, but only the simple “find & replace” up till now, never the regex ones. So I am not sure whether it is possible to achieve what I intend to do. Anyway, here are my data:

    example.png

    There are two things I am hoping to do with it:

    1. to change all the individual “0” into “0.000”. So the 2nd (and 18th, 22th, 24th, 25th etc.) line should become 0.000, but other lines should stay the same, like the 6th line should still be “0.006”.

    2. to replace all the lines contains “e-XX” to “0.000”.
      For example, the 3-5 line should all become “0.000”.
      Don’t know this would make things easier or not but: all these lines that contain “e-XX” have the same length (9 characters).

    About my data file though, there are few hundred files like this one, and all have the same number of lines, around 193000.
    Here is a part of it:

    19760101
    0
    1.974e-05
    3.949e-06
    2.764e-05
    0.006
    0.001
    0.001
    0.000
    0.000
    0.000
    0.000
    0.001
    0.002
    0.001
    0.001
    0.000
    0
    0.011
    0.071
    0.002
    0
    9.969e-05
    0
    0
    0
    0
    0.000
    0
    0
    0
    0
    0.000
    0.003
    0.002
    0.002
    6.319e-05
    0
    0.000
    6.319e-05
    0.000
    0
    0
    0
    0

    Please help me out, thanks a TON!

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 Jan 26, 2022, 7:58 AM Jan 26, 2022, 7:55 AM

      Hello, @moking-c and All,

      • Open the Replace dialog ( Ctrl + H )

        • SEARCH (?-is)^0$|^.+e-.+

        • REPLACE 0.000

        • Tick the Wrap around option

        • Select the Regular expression search mode

        • Click once, on the Replace All button

      • Close the Replace dialog ( ESC )

      Voila !

      In order to verify, you may use, first, the Replace button, a few times, before clicking on the Replace All button !

      Best Regards,

      guy038

      M 2 Replies Last reply Jan 26, 2022, 8:05 AM Reply Quote 1
      • M
        Moking C @guy038
        last edited by Jan 26, 2022, 8:05 AM

        @guy038 Wow, thank you so much for the help! I tried and it works perfectly.

        1 Reply Last reply Reply Quote 0
        • M
          Moking C @guy038
          last edited by Jan 26, 2022, 8:09 AM

          @guy038 Could you please kindly explain this: (?-is)^0$|^.+e-.+
          I understand it contains several parts but have no idea of their meanings.
          I want to understand it so I can hopefully modify it in the future in case some similar problem came up.

          1 Reply Last reply Reply Quote 0
          • G
            guy038
            last edited by guy038 Jan 26, 2022, 8:33 AM Jan 26, 2022, 8:15 AM

            Hi, @moking-c and All,

            You’re right about wanting a full insight of the solution. Hopefully, this regex is not very difficult to understand :

            • The ^0$ part searches for a single 0 between beginning of line ( ^ ) and end ( $ ) of current line

            • The ^.+e-.+ part searches, from beginning of line ( ^ ), for any non-null text, followed with the string e- , with this exact case, and followed with any non-null text ,again, till the end of line

            • At beginning, the part (?-is) part are in-line modifiers which mean :

              • Any regex . symbol refer to a single standard character ( Not EOL ones ) : modifier -s

              • Any search is sensible to case : modifier -i ( not insensible ! )


            For further learning about regexes, see :

            • The official N++ documentation : https://npp-user-manual.org/docs/searching/#regular-expressions

            • The Regex FAQ : https://community.notepad-plus-plus.org/topic/15765/faq-desk-where-to-find-regular-expressions-regex-documentation

            Best Regards,

            guy038

            M 1 Reply Last reply Jan 26, 2022, 8:21 AM Reply Quote 2
            • M
              Moking C @guy038
              last edited by Jan 26, 2022, 8:21 AM

              @guy038 Can’t say I 100% understood but thank you. Have a nice day :)

              A 1 Reply Last reply Jan 26, 2022, 12:43 PM Reply Quote 0
              • A
                Alan Kilborn @Moking C
                last edited by Jan 26, 2022, 12:43 PM

                @moking-c said in Need help with replacing/editing lines!:

                Can’t say I 100% understood

                I might say things differently from Guy – does it help any with understanding?:

                • Instead of non-null text I would say “one or more characters”.

                • Instead of Any regex . symbol refer to a single standard character ( Not EOL ones ) I would say “any . in the expression can match any character except line-ending characters (carriage return or linefeed)”

                • Instead of Any search is sensible to case : modifier -i ( not insensible ! ) I would say “-i means to not (from the minus) ignore (from the i) case of the characters, thus case (of the e) is relevant”

                I don’t know if helps, but it is another way of saying these things.

                M 1 Reply Last reply Jan 27, 2022, 3:19 AM Reply Quote 3
                • M
                  Moking C @Alan Kilborn
                  last edited by Jan 27, 2022, 3:19 AM

                  @alan-kilborn thank you it helps ;)

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