user2845645
user2845645

Reputation: 21

How to add names to columns of a csv file with awk

I have a .csv file with four columns, lacking the headline. I have to insert a new line with the names for each columns. How can I do this?

Upvotes: 0

Views: 509

Answers (2)

Isidor Lipsch
Isidor Lipsch

Reputation: 51

I'm sure there are more sophisticated approaches, but a very blunt way is to create a header file with:

printf "SNP BP A1 TEST NMISS OR SE L95 U95 STAT P\n" > header

(use names of your column separated by space) and then do

cat header myfile.txt > myfile.withheader.txt

provided that your myfile.txt is also space-separated.

Upvotes: 0

jlliagre
jlliagre

Reputation: 30873

No need to use awk for this:

(
    printf "label1 label2 label3 label4\n"
    cat file.csv
) > file1.csv

Upvotes: 1

Related Questions