how to print a string in a column? [duplicate]

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











up vote
0
down vote

favorite













This question already has an answer here:



  • Transpose N rows with different columns into single column

    5 answers



I've one string with this format:



A B C D


How can I have the same pattern in a column?







share|improve this question














marked as duplicate by RomanPerekhrest, Jeff Schaller, Kiwy, Timothy Martin, G-Man Mar 16 at 7:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















    up vote
    0
    down vote

    favorite













    This question already has an answer here:



    • Transpose N rows with different columns into single column

      5 answers



    I've one string with this format:



    A B C D


    How can I have the same pattern in a column?







    share|improve this question














    marked as duplicate by RomanPerekhrest, Jeff Schaller, Kiwy, Timothy Martin, G-Man Mar 16 at 7:32


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:



      • Transpose N rows with different columns into single column

        5 answers



      I've one string with this format:



      A B C D


      How can I have the same pattern in a column?







      share|improve this question















      This question already has an answer here:



      • Transpose N rows with different columns into single column

        5 answers



      I've one string with this format:



      A B C D


      How can I have the same pattern in a column?





      This question already has an answer here:



      • Transpose N rows with different columns into single column

        5 answers









      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 15 at 10:36









      Jeff Schaller

      31.2k846105




      31.2k846105










      asked Mar 15 at 7:00









      Luca

      183




      183




      marked as duplicate by RomanPerekhrest, Jeff Schaller, Kiwy, Timothy Martin, G-Man Mar 16 at 7:32


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by RomanPerekhrest, Jeff Schaller, Kiwy, Timothy Martin, G-Man Mar 16 at 7:32


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          Starting with this string:



          s='A B C D'


          If we want to make it print as a column, we can use bash:



          $ echo "$s// /$'n'"
          A
          B
          C
          D


          Or, using sed:



          $ sed 's/ /n/g' <<<"$s"
          A
          B
          C
          D


          Or, using tr:



          $ tr ' ' 'n' <<<"$s"
          A
          B
          C
          D


          Or, using awk:



          $ awk '$1==$1' RS=' ' ORS='n' <<<"$s"
          A
          B
          C
          D


          Or, using grep:



          $ grep -o '[[:alpha:]]' <<<"$s"
          A
          B
          C
          D





          share|improve this answer





























            up vote
            0
            down vote













            $ printf '%sn' A B C D
            A
            B
            C
            D


            The printf command, which is a built-in command in most shells, takes a formatting string containing one or several placeholders. The %s string is the placeholder for "a string" (which is what you have most commonly in the shell). If there are more arguments given to printf then there are placeholders in the format string (as in this case), the whole format string will be applied again and again until the argument list is exhausted. Since there is a n (newline) at the end of the format string, you will therefore get each letter on its own line.



            If you have the string in a variable:



            str='A B C D'
            printf '%sn' $str


            This will have the same result as above. The $str expansion is unquoted, which means that the string's content will be split on the spaces (the characters in the variable IFS will be used to split the string into words, and this variable contains by default a space, tab and a newline). Note that if the string contains filename globbing characters, such as *, then the filenames matching these patterns will be outputted. By setting the noglob shell option (with set -f or set -o noglob), you may avoid this:



            str='A B C D *'
            set -f
            printf '%sn' $str
            set +f





            share|improve this answer





























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              2
              down vote













              Starting with this string:



              s='A B C D'


              If we want to make it print as a column, we can use bash:



              $ echo "$s// /$'n'"
              A
              B
              C
              D


              Or, using sed:



              $ sed 's/ /n/g' <<<"$s"
              A
              B
              C
              D


              Or, using tr:



              $ tr ' ' 'n' <<<"$s"
              A
              B
              C
              D


              Or, using awk:



              $ awk '$1==$1' RS=' ' ORS='n' <<<"$s"
              A
              B
              C
              D


              Or, using grep:



              $ grep -o '[[:alpha:]]' <<<"$s"
              A
              B
              C
              D





              share|improve this answer


























                up vote
                2
                down vote













                Starting with this string:



                s='A B C D'


                If we want to make it print as a column, we can use bash:



                $ echo "$s// /$'n'"
                A
                B
                C
                D


                Or, using sed:



                $ sed 's/ /n/g' <<<"$s"
                A
                B
                C
                D


                Or, using tr:



                $ tr ' ' 'n' <<<"$s"
                A
                B
                C
                D


                Or, using awk:



                $ awk '$1==$1' RS=' ' ORS='n' <<<"$s"
                A
                B
                C
                D


                Or, using grep:



                $ grep -o '[[:alpha:]]' <<<"$s"
                A
                B
                C
                D





                share|improve this answer
























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Starting with this string:



                  s='A B C D'


                  If we want to make it print as a column, we can use bash:



                  $ echo "$s// /$'n'"
                  A
                  B
                  C
                  D


                  Or, using sed:



                  $ sed 's/ /n/g' <<<"$s"
                  A
                  B
                  C
                  D


                  Or, using tr:



                  $ tr ' ' 'n' <<<"$s"
                  A
                  B
                  C
                  D


                  Or, using awk:



                  $ awk '$1==$1' RS=' ' ORS='n' <<<"$s"
                  A
                  B
                  C
                  D


                  Or, using grep:



                  $ grep -o '[[:alpha:]]' <<<"$s"
                  A
                  B
                  C
                  D





                  share|improve this answer














                  Starting with this string:



                  s='A B C D'


                  If we want to make it print as a column, we can use bash:



                  $ echo "$s// /$'n'"
                  A
                  B
                  C
                  D


                  Or, using sed:



                  $ sed 's/ /n/g' <<<"$s"
                  A
                  B
                  C
                  D


                  Or, using tr:



                  $ tr ' ' 'n' <<<"$s"
                  A
                  B
                  C
                  D


                  Or, using awk:



                  $ awk '$1==$1' RS=' ' ORS='n' <<<"$s"
                  A
                  B
                  C
                  D


                  Or, using grep:



                  $ grep -o '[[:alpha:]]' <<<"$s"
                  A
                  B
                  C
                  D






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 15 at 7:07

























                  answered Mar 15 at 7:03









                  John1024

                  44k499115




                  44k499115






















                      up vote
                      0
                      down vote













                      $ printf '%sn' A B C D
                      A
                      B
                      C
                      D


                      The printf command, which is a built-in command in most shells, takes a formatting string containing one or several placeholders. The %s string is the placeholder for "a string" (which is what you have most commonly in the shell). If there are more arguments given to printf then there are placeholders in the format string (as in this case), the whole format string will be applied again and again until the argument list is exhausted. Since there is a n (newline) at the end of the format string, you will therefore get each letter on its own line.



                      If you have the string in a variable:



                      str='A B C D'
                      printf '%sn' $str


                      This will have the same result as above. The $str expansion is unquoted, which means that the string's content will be split on the spaces (the characters in the variable IFS will be used to split the string into words, and this variable contains by default a space, tab and a newline). Note that if the string contains filename globbing characters, such as *, then the filenames matching these patterns will be outputted. By setting the noglob shell option (with set -f or set -o noglob), you may avoid this:



                      str='A B C D *'
                      set -f
                      printf '%sn' $str
                      set +f





                      share|improve this answer


























                        up vote
                        0
                        down vote













                        $ printf '%sn' A B C D
                        A
                        B
                        C
                        D


                        The printf command, which is a built-in command in most shells, takes a formatting string containing one or several placeholders. The %s string is the placeholder for "a string" (which is what you have most commonly in the shell). If there are more arguments given to printf then there are placeholders in the format string (as in this case), the whole format string will be applied again and again until the argument list is exhausted. Since there is a n (newline) at the end of the format string, you will therefore get each letter on its own line.



                        If you have the string in a variable:



                        str='A B C D'
                        printf '%sn' $str


                        This will have the same result as above. The $str expansion is unquoted, which means that the string's content will be split on the spaces (the characters in the variable IFS will be used to split the string into words, and this variable contains by default a space, tab and a newline). Note that if the string contains filename globbing characters, such as *, then the filenames matching these patterns will be outputted. By setting the noglob shell option (with set -f or set -o noglob), you may avoid this:



                        str='A B C D *'
                        set -f
                        printf '%sn' $str
                        set +f





                        share|improve this answer
























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          $ printf '%sn' A B C D
                          A
                          B
                          C
                          D


                          The printf command, which is a built-in command in most shells, takes a formatting string containing one or several placeholders. The %s string is the placeholder for "a string" (which is what you have most commonly in the shell). If there are more arguments given to printf then there are placeholders in the format string (as in this case), the whole format string will be applied again and again until the argument list is exhausted. Since there is a n (newline) at the end of the format string, you will therefore get each letter on its own line.



                          If you have the string in a variable:



                          str='A B C D'
                          printf '%sn' $str


                          This will have the same result as above. The $str expansion is unquoted, which means that the string's content will be split on the spaces (the characters in the variable IFS will be used to split the string into words, and this variable contains by default a space, tab and a newline). Note that if the string contains filename globbing characters, such as *, then the filenames matching these patterns will be outputted. By setting the noglob shell option (with set -f or set -o noglob), you may avoid this:



                          str='A B C D *'
                          set -f
                          printf '%sn' $str
                          set +f





                          share|improve this answer














                          $ printf '%sn' A B C D
                          A
                          B
                          C
                          D


                          The printf command, which is a built-in command in most shells, takes a formatting string containing one or several placeholders. The %s string is the placeholder for "a string" (which is what you have most commonly in the shell). If there are more arguments given to printf then there are placeholders in the format string (as in this case), the whole format string will be applied again and again until the argument list is exhausted. Since there is a n (newline) at the end of the format string, you will therefore get each letter on its own line.



                          If you have the string in a variable:



                          str='A B C D'
                          printf '%sn' $str


                          This will have the same result as above. The $str expansion is unquoted, which means that the string's content will be split on the spaces (the characters in the variable IFS will be used to split the string into words, and this variable contains by default a space, tab and a newline). Note that if the string contains filename globbing characters, such as *, then the filenames matching these patterns will be outputted. By setting the noglob shell option (with set -f or set -o noglob), you may avoid this:



                          str='A B C D *'
                          set -f
                          printf '%sn' $str
                          set +f






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 15 at 7:34

























                          answered Mar 15 at 7:27









                          Kusalananda

                          103k13201318




                          103k13201318












                              Popular posts from this blog

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

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?