Skip to content

Commit

Permalink
port examples/netstat.nu
Browse files Browse the repository at this point in the history
- replace all '-' with '_'
- `keep until` -> `take until`
- explicit `$it`
- `str collect` -> `str join`
- `str find-replace` -> `str replace`
- "\[ \]" -> to the raw '\[ \]'
- `if {} {}` -> `if {} else {}`
- explicit print
  • Loading branch information
39555 committed May 25, 2024
1 parent 6336a75 commit ae3d743
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions modules/examples/netstat.nu
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
let ns = (netstat | lines | skip 1)

let first-batch = ($ns | keep until $it =~ Active | str collect (char nl) | from ssv -m 1)
let second-batch = ($ns |
skip until $it =~ Active |
let first_batch = ($ns | take until {|it| $it =~ Active } | str join (char nl) | from ssv -m 1)
let second_batch = ($ns |
skip until {|it| $it =~ Active } |
skip 1 |
str collect (char nl) |
str find-replace "\[ \]" "[]" --all |
str join (char nl) |
str replace '\[ \]' "[]" --all |
from ssv -m 1 |
default I-Node "" |
default Path "" |
each {|row| if $row.Type == DGRAM { $row | update Path { get I-Node } | update I-Node { get State } | update State "" } { $row } }
)
default Path ""
| each {|row| if $row.Type == DGRAM {
$row | update Path { get I-Node } | update I-Node { get State } | update State ""
} else {
$row
}
}
)

print $first_batch
print $second_batch



$first-batch

$second-batch

0 comments on commit ae3d743

Please sign in to comment.