小编Abd*_*thi的帖子

用于修剪换行符 \n 和额外空白的 Bash 替代方法

我正在尝试解析一个多行句子:

You have to go tomorrow by
                                        car.
Run Code Online (Sandbox Code Playgroud)

如您所见,有一个新的 line + space 然后是“car”。

我使用了这个正则表达式:

You.have.to.go.tomorrow.by.\n.+
Run Code Online (Sandbox Code Playgroud)

当我将它与regex101一起使用时效果很好,但是当我在 bash 中使用它时,它仅适用于第一句话:

Parser='You.have.to.go.tomorrow.by.\n.+'
Run Code Online (Sandbox Code Playgroud)

结果:

You have to go tomorrow by
Run Code Online (Sandbox Code Playgroud)

我正在使用 bash,我想要完整的句子:

"You have to go tomorrow by car."
Run Code Online (Sandbox Code Playgroud)

我在用:

sed -e 's/<[^>]\+>/ /g' | grep -oP $parser
Run Code Online (Sandbox Code Playgroud)

删除所有 HTML 标签,然后 grep 解析器。

command-line bash scripts kubuntu text-processing

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

标签 统计

bash ×1

command-line ×1

kubuntu ×1

scripts ×1

text-processing ×1