Logging 如何修剪一个巨大的文本文件?

Logging 如何修剪一个巨大的文本文件?,logging,trim,irc,Logging,Trim,Irc,所以我已经使用了大约8个月了,它记录了一个raw.log,记录了它运行的IRC频道中发生的一切。现在,问题是它记录了很多不必要的,嗯,膨胀 下面是一个例子: <<1419986827.01 :BotSelig!willie@Snoonet-bhs.ien.kdgglt.IP NICK Snoo62763 >>1419986827.04 PRIVMSG Snoo62763 :TypeError: not all arguments converted during stri

所以我已经使用了大约8个月了,它记录了一个raw.log,记录了它运行的IRC频道中发生的一切。现在,问题是它记录了很多不必要的,嗯,膨胀

下面是一个例子:

<<1419986827.01 :BotSelig!willie@Snoonet-bhs.ien.kdgglt.IP NICK Snoo62763
>>1419986827.04 PRIVMSG Snoo62763 :TypeError: not all arguments converted during string formatting (file "C:\Python27\willie\willie\coretasks.py", line 254, in track_nicks)
<<1419986827.12 :Snoo62763!willie@Snoonet-bhs.ien.kdgglt.IP PRIVMSG Snoo62763 :TypeError: not all arguments converted during string formatting (file "C:\Python27\willie\willie\coretasks.py", line 254, in track_nicks)
<<1419986827.22 :NickServ!NickServ@services.snoonet.org NOTICE Snoo62763 :Welcome to Snoonet, Snoo62763! Here on Snoonet, we provide services to enable the registration of nicknames and channels! For details, type /msg NickServ help and /msg ChanServ help.
<<1419986832.84 :venn177!venn177@user/venn177 PRIVMSG #RLB :uh, well, this seems to work
<<1419986832.84 :venn177!venn177@user/venn177 PRIVMSG #RLB :in any case, let's try this
>>1419986852.92 QUIT :KeyboardInterrupt
>>1419986861.61 CAP LS
>>1419986861.61 NICK BotSelig
>>1419986861.62 USER willie +iw BotSelig :Willie Embosbot, http://willie.dftba.net
<<1419986861.67 :veronica.snoonet.org NOTICE Auth :*** Looking up your hostname...

下面是一个Perl解决方案:

perl -i -ne 'print if s/^.*?#RLB ://' log.txt
(我假设使用unixish shell。在Windows中,单引号不起作用,您必须使用双引号:
-ne”…

-i
表示它在适当的位置修改文件。
-n
为每行运行提供的代码。
-e…
在命令行上指定正确的代码

代码本身使用基于正则表达式的搜索/替换指令。我们在找

^       # beginning of line
.*?     # anything (any character, 0 or more times, as few as possible)
#RLB :  # the text "#RLB :"
然后什么都不替换它,从而移除它。这只在后面留下文本

我们仅输出成功修改的行。这将有效地过滤掉所有其他行,留下消息

^       # beginning of line
.*?     # anything (any character, 0 or more times, as few as possible)
#RLB :  # the text "#RLB :"