Read a Csv file with powershell and capture corresponding data -


using powershell capture user input, compare input data in comma delimited csv file , write corresponding data variable.

example:

  1. a user prompted “store_number”, enter "10".
  2. the input, “10” compared data in first position or column of csv file.
  3. data, such “district_number” in corresponding position / column captured , written variable.

i have gotten method work excel file (.xlsx) have found terribly slow. hoping powershell can read csv file more efficiently.

link example csv file here:

store_number,region,district,no_of_devices,go_live_date 1,2,230,10,2/21/2013 2,2,230,10,2/25/2013 3,2,260,12,3/8/2013 4,2,230,10,3/4/2013 5,2,260,10,3/4/2013 6,2,260,10,3/11/2013 7,2,230,10,2/25/2013 8,2,230,10,3/4/2013 9,2,260,10,5/1/2013 10,6,630,10,5/23/2013 

what should looking @ import-csv

once import csv can use column header variable.

example csv:

name  | phone number | email elvis | 867.5309     | elvis@geocities.com sammy | 555.1234     | samsosa@hotmail.com 

now import csv, , loop through list add array. can compare value input array:

$name = @() $phone = @()  import-csv h:\programs\scripts\sometext.csv |`     foreach-object {         $name += $_.name         $phone += $_."phone number"     }  $inputnumber = read-host -prompt "phone number"  if ($phone -contains $inputnumber)     {     write-host "customer exists!"     $where = [array]::indexof($phone, $inputnumber)     write-host "customer name: " $name[$where]     } 

and here output:

i found sammy


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -