Using RG to find and have Nushell show the results as a table
rg ' get -o' - g ' *.nu' -- max-depth 1 -- json
| from ndjson
| where type == " match"
| each {|row |
{
file : $row.data.path.text
line : $row.data.line_number
text : ($row.data.lines.text | str trim )
}
}
| group-by file
| transpose file matches
╭───┬───────────────┬──────────────────────────────────────────────────────────────────────╮
│ # │ file │ matches │
├───┼───────────────┼──────────────────────────────────────────────────────────────────────┤
│ 0 │ auto_KO.nu │ ╭───┬────────────┬──────┬───────────────╮ │
│ │ │ │ # │ file │ line │ text │ │
│ │ │ ├───┼────────────┼──────┼───────────────┤ │
│ │ │ │ 0 │ auto_KO.nu │ 75 │ | get -o $col │ │
│ │ │ ╰───┴────────────┴──────┴───────────────╯ │
│ 1 │ bible.nu │ ╭───┬──────────┬──────┬────────────────────────────────────────────╮ │
│ │ │ │ # │ file │ line │ text │ │
│ │ │ ├───┼──────────┼──────┼────────────────────────────────────────────┤ │
│ │ │ │ 0 │ bible.nu │ 45 │ | where {|w| ($stop | get -o $w) == null } │ │
│ │ │ ╰───┴──────────┴──────┴────────────────────────────────────────────╯ │
│ 2 │ ping_hosts.nu │ ╭───┬───────────────┬──────┬──────────────────────────────────────╮ │
│ │ │ │ # │ file │ line │ text │ │
│ │ │ ├───┼───────────────┼──────┼──────────────────────────────────────┤ │
│ │ │ │ 0 │ ping_hosts.nu │ 27 │ let ip = ($parsed | get -o 0.ip) │ │
│ │ │ │ 1 │ ping_hosts.nu │ 28 │ let time = ($parsed | get -o 0.time) │ │
│ │ │ ╰───┴───────────────┴──────┴──────────────────────────────────────╯ │
╰───┴───────────────┴──────────────────────────────────────────────────────────────────────╯
nuls
| where ext == ' nu'
| get name
| each {|file |
let matches = (
open $file
| decode utf-8
| lines
| enumerate
| each {|row | { file : $file line_number : ($row.index + 1 ), line : $row.item } }
| where line =~ ' get -o'
# | find 'get -o'
| str trim
| rename file line text
)
if ($matches | is-not-empty ) {
{
file : $file
matches : $matches
}
}
}
| compact
╭───┬───────────────┬───────────────────────────────────────────────────────────────────────────╮
│ # │ file │ matches │
├───┼───────────────┼───────────────────────────────────────────────────────────────────────────┤
│ 0 │ auto_ko.nu │ ╭───┬────────────┬──────┬────────────────────────────╮ │
│ │ │ │ # │ file │ line │ text │ │
│ │ │ ├───┼────────────┼──────┼────────────────────────────┤ │
│ │ │ │ 0 │ auto_ko.nu │ 75 │ | get -o $col │ │
│ │ │ ╰───┴────────────┴──────┴────────────────────────────╯ │
│ 1 │ bible.nu │ ╭───┬──────────┬──────┬──────────────────────────────────────────────╮ │
│ │ │ │ # │ file │ line │ text │ │
│ │ │ ├───┼──────────┼──────┼──────────────────────────────────────────────┤ │
│ │ │ │ 0 │ bible.nu │ 45 │ | where {|w| ($stop | get -o $w) == null } │ │
│ │ │ ╰───┴──────────┴──────┴──────────────────────────────────────────────╯ │
│ 2 │ ping_hosts.nu │ ╭───┬───────────────┬──────┬────────────────────────────────────────────╮ │
│ │ │ │ # │ file │ line │ text │ │
│ │ │ ├───┼───────────────┼──────┼────────────────────────────────────────────┤ │
│ │ │ │ 0 │ ping_hosts.nu │ 27 │ let ip = ($parsed | get -o 0.ip) │ │
│ │ │ │ 1 │ ping_hosts.nu │ 28 │ let time = ($parsed | get -o 0.time) │ │
│ │ │ ╰───┴───────────────┴──────┴────────────────────────────────────────────╯ │
╰───┴───────────────┴───────────────────────────────────────────────────────────────────────────╯