Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the header of a csv file and print it as a column using linux?

Tags:

linux

csv

I am trying to get the header or the first line of a csv file and print it as a column.

file example: test.txt name^lastname^address^zipcode^phonenumber

expected result:

name
lastname
address
zipcode
phonenumber
like image 318
arjun D. Avatar asked Feb 10 '23 08:02

arjun D.


2 Answers

Just do this

head -n1 test.txt | tr , '\n'
like image 186
Siva Praveen Avatar answered Feb 12 '23 23:02

Siva Praveen


head prints n lines of a file, tr replaces all occurrences of a first char with a second char

head -n1 test.txt | tr '^' '\n'
like image 34
pacholik Avatar answered Feb 12 '23 21:02

pacholik