News for hackers. Stuff that matters.
Re:Exploratory Data Analysis Using Awk by mbb70 on Friday October 06, 2023 @01:31PM (#37793571)
I'm all for this kind of exploratory hacking around before booting up python/R/Excel/duckdb, especially in constrained environments. A classic pain point is having to deal with column numbers, so I'll share my favorite trick:

`head -n1 /path/to/file.csv | tr ',' '\n' | nl | grep desired_column`

gives you the column number of desired_column

Re:Exploratory Data Analysis Using Awk by chaps on Friday October 06, 2023 @01:44PM (#37793741)
grep -n also works in place of `nl`!
Re:Exploratory Data Analysis Using Awk by tejtm on Friday October 06, 2023 @01:50PM (#37793807)
yep, without knowing about `nl` I used `...| grep -n column_header` or `...|grep -n .` to replicate the 'nl' behavior.

edit: I like your 'nl' better as it is using white space instead of colon as a separator.

Re:Exploratory Data Analysis Using Awk by bear8642 on Saturday October 07, 2023 @07:50PM (#37806576)
oh, didn't realise you could do that - I've tended to use `... |awk '{print $NF, $0}'` to add line numbers to something
Re:Exploratory Data Analysis Using Awk by patrec on Friday October 06, 2023 @02:09PM (#37794083)
Unless there is a quoted comma or an empty column beforehand (nl “helpfully” skips empty lines for numbering purposes).
Re:Exploratory Data Analysis Using Awk by i15e on Friday October 06, 2023 @04:11PM (#37795680)
Something to watch out for with nl is that by default it doesn't number empty lines. e.g.:

  $ printf 'one\n\nthree\n' | nl
     1  one

     2  three
Set -ba to enable numbering all lines.

For this use case I usually end up running cat -n instead since I find it easier to remember.