【发布时间】:2020-01-21 17:10:03
【问题描述】:
我有一个这样的示例文件。
this is a sample_file for testing single_words and
multiple_words from
file
我想要在不同文件中包含 _ 的单个单词和单词。
singlewords.txt
this
is
a
for
testing
and
from
file
multiwords.txt
sample_file
single_words
multiple_words
输入文本文件大约 30GB。执行此操作的最佳方法是什么?
从评论中添加:
试过egrep -o '\b(\w*_\w+)\b' words.txt > multiwords.txt。但不确定如何将剩余单词写入下一个文件
【问题讨论】:
-
脏但它应该可以工作:
sed -e "s/ /\n/g" your_file | grep -v "_" > singlewords.txt和sed -e "s/ /\n/g" your_file | grep "_" > multiwords.txt如果你的文件太大,你可以使用split命令分割成几个块 -
@oguzismail 试过 egrep -o '\b(\w*_\w+)\b' words.txt > multiwords.txt。但不确定如何将剩余单词写入下一个文件
-
grep 有 -v 标志,因为它只会输出不匹配的行
-
@Jotne 我们不要开始编辑大战