The text file is numbers.txt:
1;2;5;6;1;3 9;6;16;9;2 6;23;3 3;8;9
My code is:
$a = Get-Content .\numbers.txt
$maximum = 0
foreach ($i in $a) {
if ([int]$i.Split(";") -gt $maximum) {
$maximum = $i.Split(";")
}
}
$maximum
I know, there is something wrong with the types (string-integer), but I don't know how to fix it.
PS: If I do it this way, it works, but it's a time-consuming solution to find the max value for every column separately:
$a = Get-Content .\numbers.txt
$maximum = 0
foreach ($i in $a) {
if ([int]$i.Split(";")[0] -gt $maximum) {
$maximum = $i.Split(";")[0]
}
}
$maximum