## Create new text file based on the date of today
#mu2_20140429040401
$mu = "c:\temp\test\mu2_"
$tag = "c:\temp\test\tag_"
$Date = Get-Date
$DateStr = $Date.ToString("yyyyMMddhhmm")
$fname_mu = $mu + $DateStr + "01.txt"
$fname_tag = $tag + $DateStr + "01.txt"
$src = "c:\temp\test\mt_point.txt"
$dstDir = "C:\temp\test\test\"
$Location = "C:\temp\test\CompositeID.txt"
# Delete previous output files
Remove-Item -Path "$dstDir\*"#
$inData =New-Object -TypeName System.IO.StreamReader -ArgumentList $src
$header = $inData.ReadLine()
$header1=$inData.ReadLine()
$header2=$inData.ReadLine()
$header3=$inData.ReadLine()
$header4=$inData.ReadLine()
$header5=$inData.ReadLine()
$header6=$inData.ReadLine()
$header7=$inData.ReadLine()
$header8=$inData.ReadLine()
$header9=$inData.ReadLine()
$header10=$inData.ReadLine()
$header11=$inData.ReadLine()
$header12=$inData.ReadLine()
$header13=$inData.ReadLine()
$header14=$inData.ReadLine()
$header15=$inData.ReadLine()
$currentFile = ""
while ($line = $inData.ReadLine())
{
#echo $line
$s_point =$line -split ","
#echo $newFile
$s_point=$s_point -replace ''''
$point_ID=$s_point[2]+"."+$s_point[3]+"."+$s_point[4]+"."+$s_point[5]
#echo $point_ID
$Sel = Select-String -pattern $point_ID -path $Location
#echo $Sel
$tp_point_stirng= $Sel-split ";"
$tp_point_no=$tp_point_stirng[0]-split ":"
$tp_point=$tp_point_no[3]-split ","
if($point_ID -eq $tp_point_stirng[1])
{
if($s_point[6]-eq "T")
{
$Nis_point="!1!"+$tp_point[1]+"!"+$s_point[2]+ "!"+$tp_point_stirng[7]+"!0!SI!!"+$s_point[7]+"!!!!"+ $s_point[8]+"!"
# $Nis_point | out-file -filepath $fname_tag -Append
# $stream =New-Object System.IO.StreamWriter ($fname_tag,"True",[System.Text.Encoding]::Ascii)
# $stream.WriteLine($Nis_point)
# $stream.close()
}
}
}
使用“Select-String -pattern $ point_ID -path $ Location”非常慢,你在powershell中有更快的搜索内容文本文件吗?
示例:
a.text文件
3,44545; apa.ftp.dfv.de; FDFD; AAA; EE;
2,45433; bb.tt.uu.cc; DDDD; WWWW; TT;
搜索线对象是apa.ftp.dfv.de,如果匹配则输出该行;
3,44545; apa.ftp.dfv.de; FDFD; AAA; EE;
答案 0 :(得分:0)
$searchTerm = 'apa.ftp.dfv.de'
Get-Content .\textfile.txt | Where-Object {$_ like "*$($searchTerm)*"}