Reputation: 11
I have a csv as below I needed that formatted .
current format
a,b,c,d,e
1,2,3,4,5
Desired Output
a,
b,
c,
d,
e
1,
2,
3,
4,
5
Upvotes: 1
Views: 104
Reputation: 5201
Try a script like this:
#!/bin/bash
file=$1
cat ${file} | while read line
do
echo $line | sed 's/,/,\n/g'
echo
done
Or if you don't need a blank line after each translated lines:
cat filename.csv | sed 's/,/,\n/g'
Upvotes: 1
Reputation: 246744
You tagged bash and shell, so a bash answer:
while IFS= read -r line; do
printf "%s\n\n" "${line//,/$',\n'}"
done < file.csv
Upvotes: 0
Reputation: 122
You can try with:
sed "1G;s/,/,\n/g" file.csv
Append a new line then replace "," with ",newline"
Upvotes: 0