Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

powershell search contents of text file very slower?

$
0
0

## 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()
       
    }
    }

 

the use " Select-String  -pattern $point_ID -path $Location" very slower,do you have any search content text file in powershell faster?

 

example :
a.text file
3,44545;apa.ftp.dfv.de;fdfd;aaa;ee;
2,45433;bb.tt.uu.cc;dddd;wwww;tt;
search the line object is apa.ftp.dfv.de,if match then output the line;
3,44545;apa.ftp.dfv.de;fdfd;aaa;ee;


Viewing all articles
Browse latest Browse all 6937

Trending Articles