Community
    • Login

    Remove part of lines of text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 2.8k Views 1 Watching
    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.
    • WebMaximusW Offline
      WebMaximus
      last edited by

      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.

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @WebMaximus
        last edited by

        @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

        WebMaximusW 1 Reply Last reply Reply Quote 4
        • WebMaximusW Offline
          WebMaximus @Alan Kilborn
          last edited by

          @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!!

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA Offline
            Alan Kilborn @WebMaximus
            last edited by

            @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
            • mkupperM Offline
              mkupper
              last edited by

              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

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors