正则表达弹药

发布于 2025-02-13 19:43:54 字数 2173 浏览 3 评论 0原文

我的正则表达式需要调整,以便在匹配比赛后插入新线。有人知道如何实现这一目标吗?

例如,当我运行时:

grep -A 2 -B 6 "^Errors: [1-9]" INC0108890.txt

返回:

Backup Set: UNIX-SSH\rmg-devweb-03\Backup of web code and configuration\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:27:17 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 1
Backed up files: 1,462
Total amount: 97,617 KB
Backup Set: MySQL\rmg-db-04\Backup of MySQL Databases\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:00:05 PM
Completion: Backup completed with errors and warnings.
Warnings: 1
Errors: 1
Backed up files: 0
Total amount: 0 KB
--
Backup Set: UNIX-SSH\rmg-sysint-11\Backup of /server\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:17:13 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 87
Backed up files: 248
Total amount: 3,752,207 KB

但是,如果有人可以建议,我希望输出如下:

Backup Set: UNIX-SSH\rmg-devweb-03\Backup of web code and configuration\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:27:17 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 1
Backed up files: 1,462
Total amount: 97,617 KB

Backup Set: MySQL\rmg-db-04\Backup of MySQL Databases\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:00:05 PM
Completion: Backup completed with errors and warnings.
Warnings: 1
Errors: 1
Backed up files: 0
Total amount: 0 KB

Backup Set: UNIX-SSH\rmg-sysint-11\Backup of /server\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:17:13 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 87
Backed up files: 248
Total amount: 3,752,207 KB

My regular expression needs tweaking in order to insert a newline after a match is found. Does anyone know how to achieve this please?

For example, when I run:

grep -A 2 -B 6 "^Errors: [1-9]" INC0108890.txt

This returns:

Backup Set: UNIX-SSH\rmg-devweb-03\Backup of web code and configuration\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:27:17 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 1
Backed up files: 1,462
Total amount: 97,617 KB
Backup Set: MySQL\rmg-db-04\Backup of MySQL Databases\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:00:05 PM
Completion: Backup completed with errors and warnings.
Warnings: 1
Errors: 1
Backed up files: 0
Total amount: 0 KB
--
Backup Set: UNIX-SSH\rmg-sysint-11\Backup of /server\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:17:13 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 87
Backed up files: 248
Total amount: 3,752,207 KB

However, I desire an output as follows if anyone can advise please:

Backup Set: UNIX-SSH\rmg-devweb-03\Backup of web code and configuration\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:27:17 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 1
Backed up files: 1,462
Total amount: 97,617 KB

Backup Set: MySQL\rmg-db-04\Backup of MySQL Databases\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:00:05 PM
Completion: Backup completed with errors and warnings.
Warnings: 1
Errors: 1
Backed up files: 0
Total amount: 0 KB

Backup Set: UNIX-SSH\rmg-sysint-11\Backup of /server\rmg-asigra
Performed by: Backup Schedule: Weekdays Backup (8pm)
Started at: May 10, 2022, 8:00:01 PM
Finished at: May 10, 2022, 8:17:13 PM
Completion: Backup completed with errors.
Warnings: 0
Errors: 87
Backed up files: 248
Total amount: 3,752,207 KB

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼睛不忧郁 2025-02-20 19:43:54

- group-separator = $'\ n'应该做到这一点。

--group-separator=$'\n' should do the trick.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文