绕过 sed 反向引用限制 1 到 9 [英] Circumvent the sed backreference limit 1 through 9

查看:15
本文介绍了绕过 sed 反向引用限制 1 到 9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sed 手册明确指出可用于替代字符串中的可用反向引用编号为 1 到 9.我正在尝试解析一个包含 10 个字段的日志文件.

The sed manual clearly states that the available backreferences available for the replacement string in a substitute are numbered 1 through 9. I'm trying to parse a log file that has 10 fields.

我为它形成了正则表达式,但无法访问第十场比赛(以及之后的任何比赛).

I have the regex formed for it but the tenth match (and anything after) isn't accessible.

有没有人有一种优雅的方法来规避 KSH(或任何我可以移植到 shell 脚本的语言)中的这种限制?

Does anyone have an elegant way to circumvent this limitation in KSH (or any language that perhaps I can port to shell scripting)?

推荐答案

你可以用 perl -pe 's/(match)(str)/$2$1/g;' 代替 sed?绕过反向引用限制的方法是使用 sed 以外的其他东西.

Can you user perl -pe 's/(match)(str)/$2$1/g;' in place of sed? The way to circumvent the backreference limit is to use something other than sed.

另外,我想你可以分两步完成你的替换,但我不知道你的模式,所以我无法帮助你.

Also, I suppose you could do your substitution in two steps, but I don't know your pattern so I can't help you out with how.

这篇关于绕过 sed 反向引用限制 1 到 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆