使用正则表达式转换对话IRC日志? [英] Converting conversations IRC logs with regex?
本文介绍了使用正则表达式转换对话IRC日志?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以这里有来自BNC的IRC日志,格式为(其中[AA:BB:CC]不是实际时间,只有加载时间):
So here I have IRC logs which come from a BNC in the format of (where [AA:BB:CC] is not the actual time, only the time of loading):
[AA:BB:CC] <Person1> [re:al:ts] BLAH BLAH BLAH
[AA:BB:CC] <Person2> [an:ot:he] BLAH BLAH BLAH
[AA:BB:CC] <Person3> [rr:ea:lt] BLAH BLAH BLAH
[AA:BB:CC] <Person4> [im:es:tp] BLAH BLAH BLAH
我想将其转换为:
[re:al:ts] <Person1> BLAH BLAH BLAH
[an:ot:he] <Person2> BLAH BLAH BLAH
[rr:ea:lt] <Person3> BLAH BLAH BLAH
[im:es:tp] <Person4> BLAH BLAH BLAH
这在技术上可行吗?我看到[AA:BB:CC]可以轻松删除,但是我如何保留真实的时间戳并将其移至该行的/beginning/而不删除"blah blah blah"或"s"呢?老实说,我对regex并不十分了解.
Is this technically possible? I see that [AA:BB:CC] could easily be removed, but how would I retain the real timestamps and move them to the /beginning/ of the line without removing the "blah blah blah" or ""s? To be honest, I'm not really well-versed in regex...
谢谢:) 枫
推荐答案
要解决的示例:
perl -pe 's/^\[..:..:..](.*)(\[..:..:..]) (.*)/$2$1$3/' <<EOT
[AA:BB:CC] <Person1> [re:al:ts] BLAH BLAH BLAH
[AA:BB:CC] <Person2> [an:ot:he] BLAH BLAH BLAH
[AA:BB:CC] <Person3> [rr:ea:lt] BLAH BLAH BLAH
[AA:BB:CC] <Person4> [im:es:tp] BLAH BLAH BLAH
EOT
输出:
[re:al:ts] <Person1> BLAH BLAH BLAH
[an:ot:he] <Person2> BLAH BLAH BLAH
[rr:ea:lt] <Person3> BLAH BLAH BLAH
[im:es:tp] <Person4> BLAH BLAH BLAH
如果AA,BB,CC等是数字,则在perl正则表达式中使用\d\d
代替..
.
If AA, BB, CC, ... are numbers, then use \d\d
instead of ..
in perl regex.
这篇关于使用正则表达式转换对话IRC日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文