powershell - Read line-by-line file and split values -
i need read txt file composed follow:
aa=1000,aa=320009#999999 aa=1011,aa=320303#111111 for each readed line need split "#" @ first turn
$test[0] = aa=1000,aa=320009 , $test[1]=999999 and @ second turn
$test[0] = aa=1000,aa=320003 $test[1]= 1111111 i have problems understand how use get-content or it.
# basically, get-content return array of strings such below: # $tests = get-content "c:\myfile\path\mytests.txt" $tests = @( "aa=1000,aa=320009#999999", "aa=1011,aa=320303#111111" ) $tests | %{ $test = $_ -split '#'; write-host $test[0]; write-host $test[1] } the line above equivalent to:
$tests | foreach { $test = $_ -split '#' write-host $test[0] write-host $test[1] } meaning each line of $tests (each line being materialized $_, 1 split on '#' (which produces array used in write-host statements)
Comments
Post a Comment