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.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.
-
@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),\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.