powershell删除文件中每一行的字符后的所有内容

时间:2015-03-03 21:24:21

标签: powershell

我有一个像下面这样的行的文件,我想使用powershell删除第一个"<"之后的所有内容。在文件的每一行

" 10.0.0.1"," pc1"," Microsoft Windows Server 2008 SP2< 100%-accuracy> Microsoft Windows 7 SP0 - SP1,Windows Server 2008 SP1或Windows 8< 100%-accuracy>"

" 10.0.0.2"," pc2"," Microsoft Windows Server 2008 SP2< 100%-accuracy> Microsoft Windows 7 SP0 - SP1,Windows Server 2008 SP1或Windows 8< 100%-accuracy>"

" 10.0.0.3"," pc3"," Microsoft Windows Server 2008 SP2< 100%-accuracy> Microsoft Windows 7 SP0 - SP1,Windows Server 2008 SP1或Windows 8< 100%-accuracy>"

1 个答案:

答案 0 :(得分:1)

以下是如何截断某个分隔符的行的示例:

$line = '"10.0.0.1","pc1","Microsoft Windows Server 2008 SP2 <100%-accuracy> Microsoft Windows 7 SP0 - SP1, Windows Server 2008 SP1, or Windows 8 <100%-accuracy>"'

$linetruncated = $line.Substring(0,$line.IndexOf('<'))