Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Text-processing-2/PowerShell/text-processing-2-1.psh
Normal file
23
Task/Text-processing-2/PowerShell/text-processing-2-1.psh
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
$dateHash = @{}
|
||||
$goodLineCount = 0
|
||||
get-content c:\temp\readings.txt |
|
||||
ForEach-Object {
|
||||
$line = $_.split(" |`t",2)
|
||||
if ($dateHash.containskey($line[0])) {
|
||||
$line[0] + " is duplicated"
|
||||
} else {
|
||||
$dateHash.add($line[0], $line[1])
|
||||
}
|
||||
$readings = $line[1].split()
|
||||
$goodLine = $true
|
||||
if ($readings.count -ne 48) { $goodLine = $false; "incorrect line length : $line[0]" }
|
||||
for ($i=0; $i -lt $readings.count; $i++) {
|
||||
if ($i % 2 -ne 0) {
|
||||
if ([int]$readings[$i] -lt 1) {
|
||||
$goodLine = $false
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($goodLine) { $goodLineCount++ }
|
||||
}
|
||||
[string]$goodLineCount + " good lines"
|
||||
20
Task/Text-processing-2/PowerShell/text-processing-2-2.psh
Normal file
20
Task/Text-processing-2/PowerShell/text-processing-2-2.psh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
$dateHash = @{}
|
||||
$goodLineCount = 0
|
||||
ForEach ($rawLine in ( get-content c:\temp\readings.txt) ){
|
||||
$line = $rawLine.split(" |`t",2)
|
||||
if ($dateHash.containskey($line[0])) {
|
||||
$line[0] + " is duplicated"
|
||||
} else {
|
||||
$dateHash.add($line[0], $line[1])
|
||||
}
|
||||
$readings = [regex]::matches($line[1],"\d+\.\d+\s-?\d")
|
||||
if ($readings.count -ne 24) { "incorrect number of readings for date " + $line[0] }
|
||||
$goodLine = $true
|
||||
foreach ($flagMatch in [regex]::matches($line[1],"\d\.\d*\s(?<flag>-?\d)")) {
|
||||
if ([int][string]$flagMatch.groups["flag"].value -lt 1) {
|
||||
$goodLine = $false
|
||||
}
|
||||
}
|
||||
if ($goodLine) { $goodLineCount++}
|
||||
}
|
||||
[string]$goodLineCount + " good lines"
|
||||
Loading…
Add table
Add a link
Reference in a new issue