grep -n also works in place of `nl`!
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
Unless there is a quoted comma or an empty column beforehand (nl “helpfully” skips empty lines for numbering purposes).
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.
`head -n1 /path/to/file.csv | tr ',' '\n' | nl | grep desired_column`
gives you the column number of desired_column