问题是,我无法避免使用包含新行的超大文件:
<a>text1</a>...gigabytes of data here, all in one single line...[a text to extract b>
如果我想从这个文件复制匹配项(为了方便起见,将每个匹配项放在单独的行中),我应该怎么做?比如说,<b>.*?</b>
。你知道吗
如果我使用
grep -Pzo '\[a .*? b>' path/to/input.txt > path/to/output.txt
它只会给出一个错误:内存耗尽(这是一个相关的问题:grep-memory-exhausted)。
sed和awk都不允许处理这样的文件。那么,我应该如何从中提取匹配项呢?你知道吗
Grep从版本2.21开始有different behavior:
所以现在的情况是,对于二进制数据,所有的非文本字节 (包括换行符)被视为行终止符。如果你想改变这个 行为,你可以:
使用
text
。这将确保只有换行符是行终止符使用
null-data
。这将确保只有空字节是行终止符line-regexp option with null data
做了很多假设:
[a
。你知道吗b>
。你知道吗[a
和b>
之间找不到[a
。你知道吗相关问题 更多 >
编程相关推荐