正则表达弹药
我的正则表达式需要调整,以便在匹配比赛后插入新线。有人知道如何实现这一目标吗?
例如,当我运行时:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
- group-separator = $'\ n'
应该做到这一点。--group-separator=$'\n'
should do the trick.