从文件中解析多个值
我有一个文件,只有一行(一大行)需要解析。我想解析出该行中“未定义的错误代码”和“id”之间出现的值。问题是,它在同一行上多次出现,并且各处都有不同的值。下面的代码只给我最后一个实例。
cat bad_events_P2J3.xml | sed -n 's/.*Undefined error code (\(.*\))\" id.*/\1\n/p'
我怎样才能获得所有这样的实例?
I have a file that is just one line (one HUGE line) to parse. I want to parse out the value that appears between "Undefined error code" and " id" on this line. The thing is this appears multiple times on the same line with different values everywhere. The following code only gives me the last instance.
cat bad_events_P2J3.xml | sed -n 's/.*Undefined error code (\(.*\))\" id.*/\1\n/p'
How can I get all instances of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您走在正确的道路上:
请注意,
cat
是不必要的,除非您需要额外的换行符,sed
将为您提供一个换行符。我错过了这个在您的文件中多次出现的事实。在这种情况下这应该有效:
You were on the right track:
Note that
cat
is unnecessary and, unless you need an extra newline,sed
will provide one for you.I missed the fact that this appears multiple times in your file. This should work in that case: