[英]Remove long lines from text file (Notepad++/EditPlus)
I have a very big text file. 我有一个非常大的文本文件。 Every line in this textfile has a complete sentence in it. 此文本文件中的每一行都有一个完整的句子。 Now I have to remove every line/sentence with more than x characters in it and just keep the lines with <=x characters. 现在我必须删除其中包含超过x个字符的每一行/句子,并保留<= x个字符的行。
Is this even possible? 这甚至可能吗? Can i do this with Notepad++/EditPlus or Regular Expressions? 我可以使用Notepad ++ / EditPlus或正则表达式吗?
Thank you for your help! 谢谢您的帮助!
This is solution for Notepad++ 这是Notepad ++的解决方案
Choose "Regular expression" in Search Mode. 在搜索模式中选择“正则表达式”。 Make sure ". matches newline" checkbox is unchecked . 确保未选中 “。匹配换行符”复选框。
Find what: .{x}.+
找到: .{x}.+
Replace with: (empty) 替换为:(空)
If you don't want to leave an empty line after replacement: 如果您不想在更换后留下空行:
Find what: .{x}.+(\\r?\\n|\\n|$)
找到: .{x}.+(\\r?\\n|\\n|$)
Replace x
with number of your choice. 将x
替换为您选择的编号。
Using bash: 使用bash:
$ awk '{if (length($0) <= x) print $0; }' myfyle.txt
Where x
is the length. 其中x
是长度。 It will print the lines smaller than x
. 它将打印小于x
的线条。
See Awk Tutorial and Introduction for more awk goodies. 有关更多awk好东西,请参阅Awk教程和简介 。
This is the solution for Editplus version 3.70. 这是Editplus版本3.70的解决方案。
The following will delete any line that is 201 characters or more if you want to keep lines that are <= 200. 如果要保留<= 200的行,以下内容将删除任何201个字符或更多的行。
Note the comma after the 201. 注意201之后的逗号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.