I was instructed to rewrite it in bash. But while most powershell are easy to read, I just don’t understand what this block actually does !!? Any ideas?
First you need a file that is sorted by keyword, perhaps this is important!
Thanks for any ideas!
foreach ($line in $sfile) { $row = $line.split('|'); if (-not $ops[$row[1]]) { $ops[$row[1]] = 0; } if ($row[4] -eq '0') { $ops[$row[1]]++; } if ($row[4] -eq '1') { $ops[$row[1]]--; } #write-host $line $ops[$row[1]]; $prevrow = $row; }
Perhaps a little refactoring will help:
foreach ($line in $sfile) { # $row is an array of fields on this line that were separated by '|' $row = $line.split('|'); $key = $row[1] $interestingCol = $row[4] # Initialize $ops entry for key if it doesn't # exist (or if key does exist and the value is 0, $null or $false) if (-not $ops[$key]) { $ops[$key] = 0; } if ($interestingCol -eq '0') { $ops[$key]++; } elseif ($interestingCol -eq '1') { $ops[$key]--; } #write-host $line $ops[$key]; # This appears to be dead code - unless it is used later $prevrow = $row; }
'|' charater . , $row $ops var. , , , , , $ops ifs-, , 5- $row , - , , .
About:
#!/bin/bash saveIFS=$IFS while read -r line do IFS='|' row=($line) # I don't know whether this is intended to test for existence or a boolean value if [[ ! ${ops[${row[1]}] ]] then ops[${row[1]}]=0 fi if (( ${row[4]} == 0 )) then (( ops[${row[1]}]++ )) fi if (( ${row[4]} == 1 )) then (( ops[${row[1]}]-- )) fi # commented out # echo "$line ${ops[${row[1]}]} prevrow=$row done < "$sfile"
Source: https://habr.com/ru/post/1761758/More articles:Powershell - check if file is being used - scriptingC # Get full file path - c #Application Development. Should I check the primary key on the table or assume that it should be there? - javaHow to stop multiple pressing of UIButton? - iosочень большое приложение для просмотра веб-приложений - sortingiPhone Core Location: Differential pin for custom contact image - iphoneA large number of unit tests freezes with a transaction with an incompatible binder - javaFirebird and Table, lowercase field name - firebirdBuilding understanding does not work on Pydev (Python) - pythonWhen is DispatcherUnhandledException and AppDomain.UnhandledException insufficient (WPF application)? - .netAll Articles