-------------------------------------------------------------------------------- numbering columns of header lines -------------------------------------------------------------------------------- Many csv files have a header line with the names of columns. You wish to extract a few columns using awk or python. To do so you need to know the column numbers. The input file is say HeaderData.txt $ cat HeaderData.txt %Object Name, RA, Dec, z SN1054, 5.5,24, 0.0 SAndromeda, 0.75,41,0.001 First we have to extract only the first line and then assign a column number. $ head -n 1 HeaderData.txt %Object Name, RA, Dec, z Next we want to replace the "," with newline or "\nl" $ head -n1 HeaderData.txt | tr ',' '\n' | nl 1 Index 2 Object Name 3 RA 4 Dec 5 z Explanation: tr replaces every commma with a newline, nl assigns line numbers. Other solutions: ------------------------------------------------------------------------ $ gsed '1s/,/\n/g' HeaderData.txt | nl Explanation: work only on the first line; substitute "," with newline "\n". Note that sed does not accept newline, hence GNU sed (or gsed). If the file is super-long then you would not want to read the whole file. So quit after the first line $ gsed '1{s/,/\n/g;q}' HeaderData.txt | nl ------------------------------------------------------------------------ $ head -n 1 HeaderData.txt | xargs -n 1 | nl $ head -n1 HeaderData.txt | xargs -n1 | nl $ head -1 HeaderData.txt | xargs -n1 | nl ------------------------------------------------------------------------