powershell删除行的第一个字符
我正在使用 powershell 解析 JBOSS 日志文件。 典型的线路是这样的: 2011-12-08 09:01:07,636 错误 [org.apache.catalina.core.ContainerBase.[jboss.web].etc..
我想删除从字符 1 开始直到单词 ERROR 的所有字符。所以我想删除日期和时间、逗号及其后面的数字。我希望我的行以“错误”一词开头,并删除之前的所有内容。
我查看了谷歌并尝试了我发现的不同东西,但我很挣扎并且无法使其发挥作用。我尝试使用子字符串和替换,但找不到如何删除所有字符,直到出现错误一词。
任何帮助将不胜感激,
非常感谢!
I am parsing a JBOSS log file using powershell.
A typical line would being like this :
2011-12-08 09:01:07,636 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].etc..
I want to remove all the characters from character 1 until the word ERROR. So I want to remove the date and time, the coma and the number right after it. I want my lines to begin with the word ERROR and delete everything before that.
I looked on google and tried different things I have found but I struggle and can't make it work. I tried with substring and replace but can't find how to delete all characters until the word ERROR.
Any help would be greatly appreciated,
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一行将读取文件的内容(在示例 jboss.txt 中),并用 ERROR + 后面的内容替换包含 ERROR 的每一行。最后它会将结果保存到processed_jboss.txt中
This one-liner will read the contents of your file (in the example jboss.txt) and replace every line containing ERROR by ERROR + whatever follows on that line. Finally it will save the result in processed_jboss.txt
假设日志行位于字符串类型的变量中,这应该可以做到:
参考:
http://msdn.microsoft.com/en-us/library/system .string.aspx
Assuming the log line is in a variable of type string this should do it:
Reference:
http://msdn.microsoft.com/en-us/library/system.string.aspx