小编Joj*_*leo的帖子

带有 sed 的多个模式(正则表达式 AND 或条件)

我想删除不需要的数据。所以我的问题是,如果 test1 上面不包含 test1不以引号结尾,我该如何删除它?

20  /test1/catergory="Food"
20  /test1/target="Adults, \"Goblins\", Elderly,
Babies, \"Witch\",
Faries"
**This is some unwanted data to remove**
20  /test1/type="Western"
20  /test1/end=category
**This is some unwanted data to remove**
20  /test1/Purpose=
20  /test1/my_purpose="To create 
a fun-filled moment"
20  /test1/end=Purpose
Run Code Online (Sandbox Code Playgroud)

预期输出:

20  /test1/catergory="Food"
20  /test1/target="Adults, \"Goblins\", Elderly,
Babies, \"Witch\",
Faries"
20  /test1/type="Western"
20  /test1/end=category
20  /test1/Purpose=
20  /test1/my_purpose="To create 
a fun-filled moment"
20  /test1/end=Purpose
Run Code Online (Sandbox Code Playgroud)

我被这几个命令困住了:

1. grep -B1 'test1' test_long_sentence.txt
2. sed '/test1/!d' test_long_sentence.txt 
3. sed '/\"$/!d' …
Run Code Online (Sandbox Code Playgroud)

grep sed text-processing

3
推荐指数
1
解决办法
2165
查看次数

标签 统计

grep ×1

sed ×1

text-processing ×1