Reputation: 81
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
Upvotes: 4
Views: 12289
Reputation: 61
Try this:
for i in `cat test.txt`; do
IFS='^'
arr=($i)
for col in "${arr[@]}"; do
echo "$col"
done
break;
done
Upvotes: 1
Reputation: 8972
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'
Upvotes: 1