• Login
Community
  • Login

Remove part of lines of text

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 1.6k 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.
  • W
    WebMaximus
    last edited by May 1, 2023, 10:07 AM

    I have a large number of text files which all start with a line as seen below. The text after the equals sign will be different in each of these text files. My goal is to have Notepad++ remove anything after the equals sign in all files.

    This is an example what it can look like:

    afcad_path = \\?\C:\Users\richa\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\Packages\Community\gaya-simulations-airport-lirq-florence\scenery\Gaya\Florence\lirq-scene.bgl
    

    This is what I want it to look like:

    afcad_path =
    

    Simply put, remove any text after the equals sign for all lines starting with afcad_path =

    Many thanks in advance for any tip how to achieve this.

    A 1 Reply Last reply May 1, 2023, 11:16 AM Reply Quote 0
    • A
      Alan Kilborn @WebMaximus
      last edited by May 1, 2023, 11:16 AM

      @WebMaximus said in Remove part of lines of text:

      remove any text after the equals sign for all lines starting with afcad_path =

      Find: (?-s)^afcad_path =.+
      Replace: afcad_path =
      Search mode: Regular expression

      W 1 Reply Last reply May 1, 2023, 11:57 AM Reply Quote 4
      • W
        WebMaximus @Alan Kilborn
        last edited by May 1, 2023, 11:57 AM

        @Alan-Kilborn said in Remove part of lines of text:

        @WebMaximus said in Remove part of lines of text:

        remove any text after the equals sign for all lines starting with afcad_path =

        Find: (?-s)^afcad_path =.+
        Replace: afcad_path =
        Search mode: Regular expression

        Amazing, thanks a ton!!

        A 1 Reply Last reply May 1, 2023, 12:11 PM Reply Quote 0
        • A
          Alan Kilborn @WebMaximus
          last edited by May 1, 2023, 12:11 PM

          @WebMaximus

          Learn more to be able to apply such techniques on your own in the future; start HERE.

          1 Reply Last reply Reply Quote 3
          • M
            mkupper
            last edited by May 1, 2023, 4:54 PM

            I interpret “I have a large number of text files which all start with a line as seen below” in that the afcad_path thing is always on line 1, or possibly is the first non-blank line.

            I would search for (?-s)\A\R*afcad_path =\K.+ and replace with nothing (blank) in regular expression mode.

            See https://npp-user-manual.org/docs/searching/#regular-expressions but in summary, (?-s) disables . matching newline (this is the default for most people and so (?-s) is redundant but is there just in case someone has . matches newline enabled), \A is the start of the file, \R* gobbles up the blank lines, if any, afcad_path = is the header string the OP is interested in, \K says to keep everything that has been matched so far (the blank line(s) and “afcad_path =” thing), and .+ wipes out the remainder of the line.

            If the file already starts with “afcad_path =” with nothing following, or does not start with a “afcad_path =” line then the search/replace will do nothing and the file is not modified.

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