English 中文(简体)
权力取消第一行的性质
原标题:powershell remove first characters of line

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..

我想把所有特性从特性1移至ERROR。 因此,我想删除日期和时间、计算和编号。 我想从“ERROR”一词开始,删除之前的一切。

我看着眼光,并尝试了我发现的不同东西,但我却挣扎,不能让它发挥作用。 我尝试用插图和替换,但可以找到如何删除所有特性,直到ERROR。

任何帮助都将受到高度赞赏。

感谢很多!

最佳回答

该名学员将读到你档案中的内容(例如,jbos.txt)和。 最后,将在加工过程中节省

get-content jboss.txt | foreach-object {$_ -replace "^.*?(ERROR.*)", $1 } | out-file processed_jboss.txt
问题回答

假设逻辑框架为不同的类型,则应当:

$line = "2011-12-08 09:01:07,636 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].etc.."

$ErrorIndex =  $line.indexof("Error",0)
$CleanLogLine = $Line.Substring($ErrorIndex, $line.length)

Reference: http://msdn.microsoft.com/en-us/library/system.string.aspx





相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...