开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜