从输出中删除路径 [英] Remove path from output

查看:77
本文介绍了从输出中删除路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PowerShell中使用以下Select-String命令:

Using the following Select-String command in PowerShell:

Select-String -Path E:\Documents\combined0.txt -Pattern "GET /ccsetup\.exe" -AllMatches > E:\Documents\combined3.txt

创建一个输出文件,每行以路径和文件名开头,后跟冒号.例如:

creates an output file with each line starting with the path and file name followed by a colon. For example:

E:\Documents\combined0.txt:255:255.255.255 - - [31/Dec/2014:04:15:16 -0800] "GET /ccsetup.exe HTTP/1.1" 301 451 "-" "Mozilla/5.0 (compatible; SearchmetricsBot; http://www.xxxx.com/en/xxxx-bot/)"

如何删除结果中的输出文件路径名,输出文件名和冒号?

How do I get rid of the output file path name, output file name and colon in the results?

推荐答案

Select-String输出一个对象,您可以从中选择所需的属性. Get-Member命令将向您显示这些对象成员,如果您通过管道将其插入,例如:

Select-String outputs an object from which you can pick off properties that you want. The Get-Member command will show you these object members if you pipe into it e.g.:

Select-String -Path E:\Documents\combined0.txt -Pattern "GET /ccsetup\.exe" -AllMatches  | 
    Get-Member

其中一个属性是Line.因此,请尝试这种方式:

One of those properties is Line. So try it this way:

Select-String -Path E:\Documents\combined0.txt -Pattern "GET /ccsetup\.exe" -AllMatches | 
    Foreach {$_.Line} > E:\Documents\combined3.txt

这篇关于从输出中删除路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆