[英]Editing Text File to remove everything before certain character
So I'm creating a fake chat generator, I've gotten chatlogs of Twitch streams to make a massive chatlog text file.所以我正在创建一个假聊天生成器,我已经获得了 Twitch 流的聊天记录来制作一个巨大的聊天记录文本文件。 However they're formatted like this,
但是它们的格式是这样的,
[2017-10-14 05:27:17 UTC] beboh13: is this guy good
Is there a way to make a Python script to edit every line to remove the 4th space, so the message above would turn into this?有没有办法让 Python 脚本编辑每一行以删除第 4 个空格,所以上面的消息会变成这样?
is this guy good
Okay so I solved my problem, you don't actually have to use Python, I just got my text editor, did CTRL+H to bring up the replace menu, made sure that the special command thingys were on.好的,我解决了我的问题,您实际上不必使用 Python,我刚拿到文本编辑器,按 CTRL+H 调出替换菜单,确保启用了特殊命令 thingys。 (The button was a picture of
.*
) Then did .*UTC] .*:
to replace with nothing. (按钮是
.*
的图片)然后用.*UTC] .*:
替换为空。
You can change your logfile to a csv format and do the following您可以将日志文件更改为 csv 格式并执行以下操作
In [3]: import csv
In [3]: with open('twitch.csv','r') as file:
reado = csv.reader(file, delimiter= ' ')
#make sure that the delimiter in the file is a space
for row in reado:
print(' '.join(row[4:]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.