How to change a file format from rows to columns?
file format change : top to botto开发者_开发问答m <> left to right
input file format:
100
150
200
300
500
output file format should be:
100,150,200,300,500
I need to apply this in reverse, too.
Just replace the linefeeds by comma:
$ tr '\n' ',' < input.txt > output.txt
and reverse
$ tr ',' '\n' < input.txt > output.txt
#!/bin/sh
i=0
while read line ; do
i=`expr $i + 1`
if [ $i -eq 1 ] ; then
echo -e "$line\c"
else
echo -e ",$line\c"
fi
done < filename
echo
Use this shell script to convert the \n as , The drawback in the tr command is end of the line one comma will be there to overcome that use this script.
精彩评论