Reputation: 61
Have to make a header for a csv file from unix shell script. It should be like below.
"Name","Place","Pincode","officename"
Tried like below. But it is not working
s_header= echo "Name","Place","Pincode","officename"
echo s_header>>filename.csv
Thanks you
Upvotes: 1
Views: 11188
Reputation: 141
Suppose your csv file contents are in details.csv file. You create header.csv file by printing headers into it.You also can probably try below.
echo "Name","Place","Pincode","officename" > header.csv && cat details.csv >> header.csv && mv header.csv details.csv
Steps:
1)Print the headers into file name header.csv
2)Append the contents of the csv file contents(details.csv) into header.csv
3)Rename the header.csv file back to your original file details.csv
Upvotes: 1
Reputation: 176
You can use tool like sed. 1i means insert at first line.
sed -i -e '1i"Name","Place","Pincode","officename"' filename.csv
Upvotes: 7