3

I'm very early in trying to learn nushell, sorry! … I'd like to build a table with all the recursively found ".swift" source files in a folder, and then append an additional column that contains their (computed) line count.

  • I've used this answer which has an approach to finding all files with ls **/*.swift.
  • I've used this answer which has an approach to adding a computed column to a table with insert.

This has lead me to try out:

ls **/*.swift | insert lineCount { wc -l $in.name }

However, this does not seem to work. It's printing a lot of stuff, but it seems to be chunks of table output interspersed with chunks of wc output.

Thank you.

Benjohn
  • 133
  • 3

1 Answers1

3

You can do this using native Nushell commands - no need for wc which might not be available on other platforms (like Windows):

ls **/*.py | select name | insert linecount { open $in.name | lines | length }

(I'm working on .py files here)

Here's a screenshot:

Windows Terminal showing the results of the above command

Charles Roper
  • 10,879