3 ms·
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 hav
by mbb70 3y ago
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
- chaps 3y agogrep -n also works in place of `nl`!
- tejtm 3y agoyep, 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.
- bear8642 3y agooh, didn't realise you could do that - I've tended to use `... |awk '{print $NF, $0}'` to add line numbers to something
- patrec 3y agoUnless there is a quoted comma or an empty column beforehand (nl “helpfully” skips empty lines for numbering purposes).
- deleted 3y ago[deleted]
- i15e 3y agoSomething 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.