Remove part of lines of text
-
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.bglThis 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.
-
@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 -
@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 expressionAmazing, thanks a ton!!
-
Learn more to be able to apply such techniques on your own in the future; start HERE.
-
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),\Ais the start of the file,\R*gobbles up the blank lines, if any,afcad_path =is the header string the OP is interested in,\Ksays 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.
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