从文本文件中获取特定行到另一个文本文件

时间:2018-03-08 01:00:25

标签: regex bash sed grep pcregrep

我有一个包含许多行的纯文本文件,我只想获得以|V|runtime

开头的行

我尝试过:

sed -e '/^\(runtime\|\\|V\\|\)/p' test.txt > test.out.txt
sed -e '/^(runtime\|\\|V\\|)/' test.txt > test.out.txt
sed -e '/^runtime/p' -e '/^\\|V\\|/p' test.txt > test.out.txt
sed -i.bak '/^\\|V\\|\|runtime/!d' test.txt
sed -i.bak '/^(\\|V\\|\|runtime)/!d' test.txt
pcregrep -M '^(runtime|\|V\|)*' test.txt > test.out.txt
egrep '^(runtime|\|V\|)*' test.txt > test.out.txt

没有任何作用。我将获得一个空文件或重复相同的文件。

1 个答案:

答案 0 :(得分:1)

喜欢这个?首先是一些测试数据:

NavModel

然后是isActive命令:

$ cat foo
|V|
runtime
foo
相关问题