I would like to remove all lines from a textfile which contain a certain keyword.
So far I only found:
<linecontains>
<contains value="assert"/>
</linecontains>
but I don't know how to remove those lines.
Method 1: Remove lines using Bookmark feature in Notepad++ Click to select the Mark tab. Enable the Bookmark line checkbox. Set Search Mode to Normal. From the Search menu, click Bookmark, and click Remove Bookmarked Lines.
Is there a way to do this in Notepad++? In notepad++, there is a way to bookmark lines with a search, and then delete those bookmarked lines. No regex necessary. If a search is not needed, the you can bookmark the lines to remove with Ctrl+F2 , and then use menu Search => Bookmark => Remove Bookmarked Lines .
You would use that filter in a filterchain, in a task which supports the filterchain element, i.e. the built-in Concat, Copy, LoadFile, LoadProperties, Move tasks.
So, for example, copy or move the file using a filterchain containing your linecontains filter.
Use the negate
parameter on your linecontains
filter to exclude lines containing that string.
Example:
<project default="test">
<target name="test">
<copy tofile="file.txt.edit" file="file.txt">
<filterchain>
<linecontains negate="true">
<contains value="assert"/>
</linecontains>
</filterchain>
</copy>
</target>
</project>
Before:
$ cat file.txt
abc
assert
def
assert
ghi assert
jkl
After:
$ cat file.txt.edit
abc
def
jkl
To answer your followup question on applying to selected files in a directory:
<copy todir="dest">
<fileset dir="src">
<include name="**/*.txt"/>
</fileset>
<filterchain>
<linecontains negate="true">
<contains value="assert"/>
</linecontains>
</filterchain>
</copy>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With