we have the following file ( files.sum )

the first field is the name of the file

the second field is the seprator

the thired feald is the sum


we want to capture the sum of the file - config.csv


$SUM will be the third required value - 458349573

what is the power shell cli that can give the sum values according to the name of the file ?


This can be achieved with the Split command. You can simply loop through each line in files.sim, split with ":" as the delimiter and check if the 0 element in the resulting array equals your file name and if so set $sum to the 1 element of the current array. Here is an example:

$file = 'config.csv'
$seperator = ':'
foreach($line in Get-Content .\files.sum) {
    $NameAndSum = $line.split($seperator)
    if($NameAndSum[0] -eq $file){
        $Sum = $NameAndSum[1]
echo $file$seperator$sum

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.