Rows to column conversion of file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
14
down vote

favorite
5












Suppose I have a file:



File1:



PAPER TEAM MANISH NISHA GARIMA JYOUTI ........etc 


File2 I want:



PAPER 
TEAM
MANISH
NISHA
GARIMA
JYOUTI


Rows to column conversion of File1.










share|improve this question























  • If your file consists of more than one line and your output should thus have more than one column, then try this AWK script.
    – Dennis Williamson
    Nov 26 '14 at 16:16










  • Very much related question: askubuntu.com/q/461144/295286
    – Sergiy Kolodyazhnyy
    Jan 16 '17 at 13:39














up vote
14
down vote

favorite
5












Suppose I have a file:



File1:



PAPER TEAM MANISH NISHA GARIMA JYOUTI ........etc 


File2 I want:



PAPER 
TEAM
MANISH
NISHA
GARIMA
JYOUTI


Rows to column conversion of File1.










share|improve this question























  • If your file consists of more than one line and your output should thus have more than one column, then try this AWK script.
    – Dennis Williamson
    Nov 26 '14 at 16:16










  • Very much related question: askubuntu.com/q/461144/295286
    – Sergiy Kolodyazhnyy
    Jan 16 '17 at 13:39












up vote
14
down vote

favorite
5









up vote
14
down vote

favorite
5






5





Suppose I have a file:



File1:



PAPER TEAM MANISH NISHA GARIMA JYOUTI ........etc 


File2 I want:



PAPER 
TEAM
MANISH
NISHA
GARIMA
JYOUTI


Rows to column conversion of File1.










share|improve this question















Suppose I have a file:



File1:



PAPER TEAM MANISH NISHA GARIMA JYOUTI ........etc 


File2 I want:



PAPER 
TEAM
MANISH
NISHA
GARIMA
JYOUTI


Rows to column conversion of File1.







awk sed text-formatting






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 19 at 16:45









αғsнιη

16k92563




16k92563










asked Nov 26 '14 at 5:12









yisha

2464513




2464513











  • If your file consists of more than one line and your output should thus have more than one column, then try this AWK script.
    – Dennis Williamson
    Nov 26 '14 at 16:16










  • Very much related question: askubuntu.com/q/461144/295286
    – Sergiy Kolodyazhnyy
    Jan 16 '17 at 13:39
















  • If your file consists of more than one line and your output should thus have more than one column, then try this AWK script.
    – Dennis Williamson
    Nov 26 '14 at 16:16










  • Very much related question: askubuntu.com/q/461144/295286
    – Sergiy Kolodyazhnyy
    Jan 16 '17 at 13:39















If your file consists of more than one line and your output should thus have more than one column, then try this AWK script.
– Dennis Williamson
Nov 26 '14 at 16:16




If your file consists of more than one line and your output should thus have more than one column, then try this AWK script.
– Dennis Williamson
Nov 26 '14 at 16:16












Very much related question: askubuntu.com/q/461144/295286
– Sergiy Kolodyazhnyy
Jan 16 '17 at 13:39




Very much related question: askubuntu.com/q/461144/295286
– Sergiy Kolodyazhnyy
Jan 16 '17 at 13:39










11 Answers
11






active

oldest

votes

















up vote
14
down vote













Using tr, replace each repeated space character() with a single new-line(n) character.



tr -s ' ' 'n'< infile > outfile



But I think you want something like this?




1 2 3 4 1 a #
a b c d --> 2 b $
# $ @ % 3 c @
4 d %


With awk we could do:



awk ' for (i=1; i<=NF; i++) RtoC[i]= (RtoC[i]? RtoC[i] FS $i: $i) 
END for (i in RtoC) print RtoC[i] ' infile


This joins each same filed number positon into together and in END prints the result that would be first row in first column , second row in second column, etc. Of course the input file is limited to your memory size.






share|improve this answer





























    up vote
    7
    down vote













    You could simply do this through grep. By default grep, would print the match in a separate newline .



    grep -oP 'S+' infile > outfile


    OR



    grep -o '[^[:space:]]+' infile > outfile





    share|improve this answer
















    • 1




      +1 for creative use of grep
      – Volker Siegel
      May 21 '16 at 0:25

















    up vote
    7
    down vote













    You could also use the fmt command:



    ~$ cat f
    PAPER TEAM MANISH NISHA GARIMA JYOUTI
    ~$ fmt -1 f
    PAPER
    TEAM
    MANISH
    NISHA
    GARIMA
    JYOUTI





    share|improve this answer



























      up vote
      7
      down vote













      With GNU datamash:



      $ datamash -W transpose <file
      PAPER
      TEAM
      MANISH
      NISHA
      GARIMA
      JYOUTI





      share|improve this answer




















      • datamash seems like the best tool for the task, but fascinating how many other tools could be used!
        – Mark Stewart
        Sep 19 at 20:07

















      up vote
      6
      down vote













      You can also do this using sed:



      $ sed -e 's/ */n/g' file1 > file2


      NOTE: Doesn't handle the situation where the words contain spaces.






      share|improve this answer





























        up vote
        5
        down vote













        Using awk, setting the output field separator (OFS) as the record (line) separator (RS):



        awk 'OFS=RS;$1=$11' file > file2





        share|improve this answer



























          up vote
          2
          down vote













          Using a for loop:



          for val in `cat file1` ; do echo $val >> file2; done;





          share|improve this answer



























            up vote
            0
            down vote













            You can also try using sed



            $ sed -i.bak s@' '@'n'@g infile.txt


            Please note that I am using @ as a separator for the substitution operation.
            This will also create a backup file. In case you don't need a backup remove .bak



            $ sed -i s@' '@'n'@g infile.txt





            share|improve this answer





























              up vote
              0
              down vote













              Python version:



              python -c "import sys;lines=[l.replace(' ','n') for l in sys.stdin.readlines()];print(''.join(lines))" < input.txt > output.txt


              This uses < redirection into python's stdin from input.txt and writes to output.txt using > redirection. The one-liner itself reads in all lines from stdin into a list of strings,where all spaces are replaced with newlines, and we rebuild whole text using .join() function.



              Alternative approach to avoid multiple spaces in series being replaced with newlines is to use .split() to break line into list of words. That way , we can ensure that each word is separated only by one newline



              python -c "import sys;lines=['n'.join(l.strip().split()) for l in sys.stdin.readlines()];print('n'.join(lines))" < input.txt > output.txt





              share|improve this answer



























                up vote
                0
                down vote













                Using xargs, (stolen from souravc's answer):



                xargs -n 1 < File1 > File2


                Or if any minor reformatting is needed, use printf format strings as however might be needed:



                xargs printf '%sn' < File1 > File2





                share|improve this answer





























                  up vote
                  0
                  down vote













                  My solution would be:



                  #!/bin/bash
                  cols=$(head -1 file.txt | wc -w)
                  for i in $(seq 1 $cols); do
                  cut -d ' ' -f$i file.txt | tr 'n' ' ' | sed s'/.$//'
                  echo
                  done





                  share|improve this answer




















                    Your Answer







                    StackExchange.ready(function()
                    var channelOptions =
                    tags: "".split(" "),
                    id: "106"
                    ;
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function()
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled)
                    StackExchange.using("snippets", function()
                    createEditor();
                    );

                    else
                    createEditor();

                    );

                    function createEditor()
                    StackExchange.prepareEditor(
                    heartbeatType: 'answer',
                    convertImagesToLinks: false,
                    noModals: false,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: null,
                    bindNavPrevention: true,
                    postfix: "",
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    );



                    );













                     

                    draft saved


                    draft discarded


















                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f169995%2frows-to-column-conversion-of-file%23new-answer', 'question_page');

                    );

                    Post as a guest






























                    11 Answers
                    11






                    active

                    oldest

                    votes








                    11 Answers
                    11






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    14
                    down vote













                    Using tr, replace each repeated space character() with a single new-line(n) character.



                    tr -s ' ' 'n'< infile > outfile



                    But I think you want something like this?




                    1 2 3 4 1 a #
                    a b c d --> 2 b $
                    # $ @ % 3 c @
                    4 d %


                    With awk we could do:



                    awk ' for (i=1; i<=NF; i++) RtoC[i]= (RtoC[i]? RtoC[i] FS $i: $i) 
                    END for (i in RtoC) print RtoC[i] ' infile


                    This joins each same filed number positon into together and in END prints the result that would be first row in first column , second row in second column, etc. Of course the input file is limited to your memory size.






                    share|improve this answer


























                      up vote
                      14
                      down vote













                      Using tr, replace each repeated space character() with a single new-line(n) character.



                      tr -s ' ' 'n'< infile > outfile



                      But I think you want something like this?




                      1 2 3 4 1 a #
                      a b c d --> 2 b $
                      # $ @ % 3 c @
                      4 d %


                      With awk we could do:



                      awk ' for (i=1; i<=NF; i++) RtoC[i]= (RtoC[i]? RtoC[i] FS $i: $i) 
                      END for (i in RtoC) print RtoC[i] ' infile


                      This joins each same filed number positon into together and in END prints the result that would be first row in first column , second row in second column, etc. Of course the input file is limited to your memory size.






                      share|improve this answer
























                        up vote
                        14
                        down vote










                        up vote
                        14
                        down vote









                        Using tr, replace each repeated space character() with a single new-line(n) character.



                        tr -s ' ' 'n'< infile > outfile



                        But I think you want something like this?




                        1 2 3 4 1 a #
                        a b c d --> 2 b $
                        # $ @ % 3 c @
                        4 d %


                        With awk we could do:



                        awk ' for (i=1; i<=NF; i++) RtoC[i]= (RtoC[i]? RtoC[i] FS $i: $i) 
                        END for (i in RtoC) print RtoC[i] ' infile


                        This joins each same filed number positon into together and in END prints the result that would be first row in first column , second row in second column, etc. Of course the input file is limited to your memory size.






                        share|improve this answer














                        Using tr, replace each repeated space character() with a single new-line(n) character.



                        tr -s ' ' 'n'< infile > outfile



                        But I think you want something like this?




                        1 2 3 4 1 a #
                        a b c d --> 2 b $
                        # $ @ % 3 c @
                        4 d %


                        With awk we could do:



                        awk ' for (i=1; i<=NF; i++) RtoC[i]= (RtoC[i]? RtoC[i] FS $i: $i) 
                        END for (i in RtoC) print RtoC[i] ' infile


                        This joins each same filed number positon into together and in END prints the result that would be first row in first column , second row in second column, etc. Of course the input file is limited to your memory size.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Sep 19 at 16:43

























                        answered Nov 26 '14 at 5:59









                        αғsнιη

                        16k92563




                        16k92563






















                            up vote
                            7
                            down vote













                            You could simply do this through grep. By default grep, would print the match in a separate newline .



                            grep -oP 'S+' infile > outfile


                            OR



                            grep -o '[^[:space:]]+' infile > outfile





                            share|improve this answer
















                            • 1




                              +1 for creative use of grep
                              – Volker Siegel
                              May 21 '16 at 0:25














                            up vote
                            7
                            down vote













                            You could simply do this through grep. By default grep, would print the match in a separate newline .



                            grep -oP 'S+' infile > outfile


                            OR



                            grep -o '[^[:space:]]+' infile > outfile





                            share|improve this answer
















                            • 1




                              +1 for creative use of grep
                              – Volker Siegel
                              May 21 '16 at 0:25












                            up vote
                            7
                            down vote










                            up vote
                            7
                            down vote









                            You could simply do this through grep. By default grep, would print the match in a separate newline .



                            grep -oP 'S+' infile > outfile


                            OR



                            grep -o '[^[:space:]]+' infile > outfile





                            share|improve this answer












                            You could simply do this through grep. By default grep, would print the match in a separate newline .



                            grep -oP 'S+' infile > outfile


                            OR



                            grep -o '[^[:space:]]+' infile > outfile






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 26 '14 at 6:18









                            Avinash Raj

                            2,58031127




                            2,58031127







                            • 1




                              +1 for creative use of grep
                              – Volker Siegel
                              May 21 '16 at 0:25












                            • 1




                              +1 for creative use of grep
                              – Volker Siegel
                              May 21 '16 at 0:25







                            1




                            1




                            +1 for creative use of grep
                            – Volker Siegel
                            May 21 '16 at 0:25




                            +1 for creative use of grep
                            – Volker Siegel
                            May 21 '16 at 0:25










                            up vote
                            7
                            down vote













                            You could also use the fmt command:



                            ~$ cat f
                            PAPER TEAM MANISH NISHA GARIMA JYOUTI
                            ~$ fmt -1 f
                            PAPER
                            TEAM
                            MANISH
                            NISHA
                            GARIMA
                            JYOUTI





                            share|improve this answer
























                              up vote
                              7
                              down vote













                              You could also use the fmt command:



                              ~$ cat f
                              PAPER TEAM MANISH NISHA GARIMA JYOUTI
                              ~$ fmt -1 f
                              PAPER
                              TEAM
                              MANISH
                              NISHA
                              GARIMA
                              JYOUTI





                              share|improve this answer






















                                up vote
                                7
                                down vote










                                up vote
                                7
                                down vote









                                You could also use the fmt command:



                                ~$ cat f
                                PAPER TEAM MANISH NISHA GARIMA JYOUTI
                                ~$ fmt -1 f
                                PAPER
                                TEAM
                                MANISH
                                NISHA
                                GARIMA
                                JYOUTI





                                share|improve this answer












                                You could also use the fmt command:



                                ~$ cat f
                                PAPER TEAM MANISH NISHA GARIMA JYOUTI
                                ~$ fmt -1 f
                                PAPER
                                TEAM
                                MANISH
                                NISHA
                                GARIMA
                                JYOUTI






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Nov 26 '14 at 7:42









                                fredtantini

                                2,493715




                                2,493715




















                                    up vote
                                    7
                                    down vote













                                    With GNU datamash:



                                    $ datamash -W transpose <file
                                    PAPER
                                    TEAM
                                    MANISH
                                    NISHA
                                    GARIMA
                                    JYOUTI





                                    share|improve this answer




















                                    • datamash seems like the best tool for the task, but fascinating how many other tools could be used!
                                      – Mark Stewart
                                      Sep 19 at 20:07














                                    up vote
                                    7
                                    down vote













                                    With GNU datamash:



                                    $ datamash -W transpose <file
                                    PAPER
                                    TEAM
                                    MANISH
                                    NISHA
                                    GARIMA
                                    JYOUTI





                                    share|improve this answer




















                                    • datamash seems like the best tool for the task, but fascinating how many other tools could be used!
                                      – Mark Stewart
                                      Sep 19 at 20:07












                                    up vote
                                    7
                                    down vote










                                    up vote
                                    7
                                    down vote









                                    With GNU datamash:



                                    $ datamash -W transpose <file
                                    PAPER
                                    TEAM
                                    MANISH
                                    NISHA
                                    GARIMA
                                    JYOUTI





                                    share|improve this answer












                                    With GNU datamash:



                                    $ datamash -W transpose <file
                                    PAPER
                                    TEAM
                                    MANISH
                                    NISHA
                                    GARIMA
                                    JYOUTI






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 26 '14 at 18:55









                                    cuonglm

                                    98.7k21188285




                                    98.7k21188285











                                    • datamash seems like the best tool for the task, but fascinating how many other tools could be used!
                                      – Mark Stewart
                                      Sep 19 at 20:07
















                                    • datamash seems like the best tool for the task, but fascinating how many other tools could be used!
                                      – Mark Stewart
                                      Sep 19 at 20:07















                                    datamash seems like the best tool for the task, but fascinating how many other tools could be used!
                                    – Mark Stewart
                                    Sep 19 at 20:07




                                    datamash seems like the best tool for the task, but fascinating how many other tools could be used!
                                    – Mark Stewart
                                    Sep 19 at 20:07










                                    up vote
                                    6
                                    down vote













                                    You can also do this using sed:



                                    $ sed -e 's/ */n/g' file1 > file2


                                    NOTE: Doesn't handle the situation where the words contain spaces.






                                    share|improve this answer


























                                      up vote
                                      6
                                      down vote













                                      You can also do this using sed:



                                      $ sed -e 's/ */n/g' file1 > file2


                                      NOTE: Doesn't handle the situation where the words contain spaces.






                                      share|improve this answer
























                                        up vote
                                        6
                                        down vote










                                        up vote
                                        6
                                        down vote









                                        You can also do this using sed:



                                        $ sed -e 's/ */n/g' file1 > file2


                                        NOTE: Doesn't handle the situation where the words contain spaces.






                                        share|improve this answer














                                        You can also do this using sed:



                                        $ sed -e 's/ */n/g' file1 > file2


                                        NOTE: Doesn't handle the situation where the words contain spaces.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Aug 1 '17 at 14:27









                                        Philippos

                                        5,95711546




                                        5,95711546










                                        answered Nov 26 '14 at 6:13









                                        slm♦

                                        239k65495665




                                        239k65495665




















                                            up vote
                                            5
                                            down vote













                                            Using awk, setting the output field separator (OFS) as the record (line) separator (RS):



                                            awk 'OFS=RS;$1=$11' file > file2





                                            share|improve this answer
























                                              up vote
                                              5
                                              down vote













                                              Using awk, setting the output field separator (OFS) as the record (line) separator (RS):



                                              awk 'OFS=RS;$1=$11' file > file2





                                              share|improve this answer






















                                                up vote
                                                5
                                                down vote










                                                up vote
                                                5
                                                down vote









                                                Using awk, setting the output field separator (OFS) as the record (line) separator (RS):



                                                awk 'OFS=RS;$1=$11' file > file2





                                                share|improve this answer












                                                Using awk, setting the output field separator (OFS) as the record (line) separator (RS):



                                                awk 'OFS=RS;$1=$11' file > file2






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 26 '14 at 5:30









                                                jasonwryan

                                                47.6k14131180




                                                47.6k14131180




















                                                    up vote
                                                    2
                                                    down vote













                                                    Using a for loop:



                                                    for val in `cat file1` ; do echo $val >> file2; done;





                                                    share|improve this answer
























                                                      up vote
                                                      2
                                                      down vote













                                                      Using a for loop:



                                                      for val in `cat file1` ; do echo $val >> file2; done;





                                                      share|improve this answer






















                                                        up vote
                                                        2
                                                        down vote










                                                        up vote
                                                        2
                                                        down vote









                                                        Using a for loop:



                                                        for val in `cat file1` ; do echo $val >> file2; done;





                                                        share|improve this answer












                                                        Using a for loop:



                                                        for val in `cat file1` ; do echo $val >> file2; done;






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 26 '14 at 6:55









                                                        Mandar Shinde

                                                        1,38772746




                                                        1,38772746




















                                                            up vote
                                                            0
                                                            down vote













                                                            You can also try using sed



                                                            $ sed -i.bak s@' '@'n'@g infile.txt


                                                            Please note that I am using @ as a separator for the substitution operation.
                                                            This will also create a backup file. In case you don't need a backup remove .bak



                                                            $ sed -i s@' '@'n'@g infile.txt





                                                            share|improve this answer


























                                                              up vote
                                                              0
                                                              down vote













                                                              You can also try using sed



                                                              $ sed -i.bak s@' '@'n'@g infile.txt


                                                              Please note that I am using @ as a separator for the substitution operation.
                                                              This will also create a backup file. In case you don't need a backup remove .bak



                                                              $ sed -i s@' '@'n'@g infile.txt





                                                              share|improve this answer
























                                                                up vote
                                                                0
                                                                down vote










                                                                up vote
                                                                0
                                                                down vote









                                                                You can also try using sed



                                                                $ sed -i.bak s@' '@'n'@g infile.txt


                                                                Please note that I am using @ as a separator for the substitution operation.
                                                                This will also create a backup file. In case you don't need a backup remove .bak



                                                                $ sed -i s@' '@'n'@g infile.txt





                                                                share|improve this answer














                                                                You can also try using sed



                                                                $ sed -i.bak s@' '@'n'@g infile.txt


                                                                Please note that I am using @ as a separator for the substitution operation.
                                                                This will also create a backup file. In case you don't need a backup remove .bak



                                                                $ sed -i s@' '@'n'@g infile.txt






                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Jan 16 '17 at 13:33









                                                                Kusalananda

                                                                108k14209332




                                                                108k14209332










                                                                answered Jan 16 '17 at 13:09









                                                                Vaibhav Shetye

                                                                93




                                                                93




















                                                                    up vote
                                                                    0
                                                                    down vote













                                                                    Python version:



                                                                    python -c "import sys;lines=[l.replace(' ','n') for l in sys.stdin.readlines()];print(''.join(lines))" < input.txt > output.txt


                                                                    This uses < redirection into python's stdin from input.txt and writes to output.txt using > redirection. The one-liner itself reads in all lines from stdin into a list of strings,where all spaces are replaced with newlines, and we rebuild whole text using .join() function.



                                                                    Alternative approach to avoid multiple spaces in series being replaced with newlines is to use .split() to break line into list of words. That way , we can ensure that each word is separated only by one newline



                                                                    python -c "import sys;lines=['n'.join(l.strip().split()) for l in sys.stdin.readlines()];print('n'.join(lines))" < input.txt > output.txt





                                                                    share|improve this answer
























                                                                      up vote
                                                                      0
                                                                      down vote













                                                                      Python version:



                                                                      python -c "import sys;lines=[l.replace(' ','n') for l in sys.stdin.readlines()];print(''.join(lines))" < input.txt > output.txt


                                                                      This uses < redirection into python's stdin from input.txt and writes to output.txt using > redirection. The one-liner itself reads in all lines from stdin into a list of strings,where all spaces are replaced with newlines, and we rebuild whole text using .join() function.



                                                                      Alternative approach to avoid multiple spaces in series being replaced with newlines is to use .split() to break line into list of words. That way , we can ensure that each word is separated only by one newline



                                                                      python -c "import sys;lines=['n'.join(l.strip().split()) for l in sys.stdin.readlines()];print('n'.join(lines))" < input.txt > output.txt





                                                                      share|improve this answer






















                                                                        up vote
                                                                        0
                                                                        down vote










                                                                        up vote
                                                                        0
                                                                        down vote









                                                                        Python version:



                                                                        python -c "import sys;lines=[l.replace(' ','n') for l in sys.stdin.readlines()];print(''.join(lines))" < input.txt > output.txt


                                                                        This uses < redirection into python's stdin from input.txt and writes to output.txt using > redirection. The one-liner itself reads in all lines from stdin into a list of strings,where all spaces are replaced with newlines, and we rebuild whole text using .join() function.



                                                                        Alternative approach to avoid multiple spaces in series being replaced with newlines is to use .split() to break line into list of words. That way , we can ensure that each word is separated only by one newline



                                                                        python -c "import sys;lines=['n'.join(l.strip().split()) for l in sys.stdin.readlines()];print('n'.join(lines))" < input.txt > output.txt





                                                                        share|improve this answer












                                                                        Python version:



                                                                        python -c "import sys;lines=[l.replace(' ','n') for l in sys.stdin.readlines()];print(''.join(lines))" < input.txt > output.txt


                                                                        This uses < redirection into python's stdin from input.txt and writes to output.txt using > redirection. The one-liner itself reads in all lines from stdin into a list of strings,where all spaces are replaced with newlines, and we rebuild whole text using .join() function.



                                                                        Alternative approach to avoid multiple spaces in series being replaced with newlines is to use .split() to break line into list of words. That way , we can ensure that each word is separated only by one newline



                                                                        python -c "import sys;lines=['n'.join(l.strip().split()) for l in sys.stdin.readlines()];print('n'.join(lines))" < input.txt > output.txt






                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Jan 16 '17 at 13:46









                                                                        Sergiy Kolodyazhnyy

                                                                        7,95511848




                                                                        7,95511848




















                                                                            up vote
                                                                            0
                                                                            down vote













                                                                            Using xargs, (stolen from souravc's answer):



                                                                            xargs -n 1 < File1 > File2


                                                                            Or if any minor reformatting is needed, use printf format strings as however might be needed:



                                                                            xargs printf '%sn' < File1 > File2





                                                                            share|improve this answer


























                                                                              up vote
                                                                              0
                                                                              down vote













                                                                              Using xargs, (stolen from souravc's answer):



                                                                              xargs -n 1 < File1 > File2


                                                                              Or if any minor reformatting is needed, use printf format strings as however might be needed:



                                                                              xargs printf '%sn' < File1 > File2





                                                                              share|improve this answer
























                                                                                up vote
                                                                                0
                                                                                down vote










                                                                                up vote
                                                                                0
                                                                                down vote









                                                                                Using xargs, (stolen from souravc's answer):



                                                                                xargs -n 1 < File1 > File2


                                                                                Or if any minor reformatting is needed, use printf format strings as however might be needed:



                                                                                xargs printf '%sn' < File1 > File2





                                                                                share|improve this answer














                                                                                Using xargs, (stolen from souravc's answer):



                                                                                xargs -n 1 < File1 > File2


                                                                                Or if any minor reformatting is needed, use printf format strings as however might be needed:



                                                                                xargs printf '%sn' < File1 > File2






                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited Apr 9 at 19:36

























                                                                                answered Apr 9 at 19:03









                                                                                agc

                                                                                4,3221935




                                                                                4,3221935




















                                                                                    up vote
                                                                                    0
                                                                                    down vote













                                                                                    My solution would be:



                                                                                    #!/bin/bash
                                                                                    cols=$(head -1 file.txt | wc -w)
                                                                                    for i in $(seq 1 $cols); do
                                                                                    cut -d ' ' -f$i file.txt | tr 'n' ' ' | sed s'/.$//'
                                                                                    echo
                                                                                    done





                                                                                    share|improve this answer
























                                                                                      up vote
                                                                                      0
                                                                                      down vote













                                                                                      My solution would be:



                                                                                      #!/bin/bash
                                                                                      cols=$(head -1 file.txt | wc -w)
                                                                                      for i in $(seq 1 $cols); do
                                                                                      cut -d ' ' -f$i file.txt | tr 'n' ' ' | sed s'/.$//'
                                                                                      echo
                                                                                      done





                                                                                      share|improve this answer






















                                                                                        up vote
                                                                                        0
                                                                                        down vote










                                                                                        up vote
                                                                                        0
                                                                                        down vote









                                                                                        My solution would be:



                                                                                        #!/bin/bash
                                                                                        cols=$(head -1 file.txt | wc -w)
                                                                                        for i in $(seq 1 $cols); do
                                                                                        cut -d ' ' -f$i file.txt | tr 'n' ' ' | sed s'/.$//'
                                                                                        echo
                                                                                        done





                                                                                        share|improve this answer












                                                                                        My solution would be:



                                                                                        #!/bin/bash
                                                                                        cols=$(head -1 file.txt | wc -w)
                                                                                        for i in $(seq 1 $cols); do
                                                                                        cut -d ' ' -f$i file.txt | tr 'n' ' ' | sed s'/.$//'
                                                                                        echo
                                                                                        done






                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Jun 20 at 21:31









                                                                                        Saumyakanta Sahoo

                                                                                        1




                                                                                        1



























                                                                                             

                                                                                            draft saved


                                                                                            draft discarded















































                                                                                             


                                                                                            draft saved


                                                                                            draft discarded














                                                                                            StackExchange.ready(
                                                                                            function ()
                                                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f169995%2frows-to-column-conversion-of-file%23new-answer', 'question_page');

                                                                                            );

                                                                                            Post as a guest













































































                                                                                            Popular posts from this blog

                                                                                            How to check contact read email or not when send email to Individual?

                                                                                            Bahrain

                                                                                            Postfix configuration issue with fips on centos 7; mailgun relay