Score:1

extract colname

us flag

I need to get colnames but just want one colname in each line so could you please help how to change below command.

head -n 1 betas_1.csv >col.names
Score:1
re flag
head -n 1 betas_1.csv | sed 's/,/\n/g' 
Tom Chiverton avatar
re flag
you didn't provide an example .csv file so I had to guess... edited.
Score:1
iq flag

If you want one column per line you can use awk, it can split the column names by commas, here the command for what you want:

head -n 1 betas_1.csv | awk -F ',' '{for(i=1; i<=NF; i++) print $i}' > col.names
Score:0
hr flag

Any of:

head -n 1 betas_1.csv | tr ',' '\n' >col.names

sed 's/,/\n/g;q' betas_1.csv >col.names

awk -F, 'BEGIN{OFS="\n"} {$1=$1; print; exit}' betas_1.csv >col.names

perl -F, -ne 'print join "\n", @F; last' betas_1.csv >col.names

or (using the python-based csvkit)

csvstat --names betas_1.csv >col.names

(although this includes a column index by default).

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.