how can i return the output of a text [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:



  • How can I print multiline output on the same line?

    8 answers



This is related to a question i asked in overflow, It remains unanswered so i though I'd try asking it in segments



My objective is to return the special n function, If i were to run



echo -e "My name is nnick rock and i nlive by the sea shore." > file


Then when i cat that file you get something like this



My name is
nick rock and i
live by the sea shore.


What I'm looking to do is reverse the n return function, so when i echo the file with something like this



echo -aoE '([a-zA-Z])1,5' file

output
My
name
is
nick
rock
and
i
live
by
the
sea
shore.


I'll get this instead



My name is nick rock and i live by the sea shore






share|improve this question














marked as duplicate by Sergiy Kolodyazhnyy command-line
Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jun 1 at 0:07


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:



    • How can I print multiline output on the same line?

      8 answers



    This is related to a question i asked in overflow, It remains unanswered so i though I'd try asking it in segments



    My objective is to return the special n function, If i were to run



    echo -e "My name is nnick rock and i nlive by the sea shore." > file


    Then when i cat that file you get something like this



    My name is
    nick rock and i
    live by the sea shore.


    What I'm looking to do is reverse the n return function, so when i echo the file with something like this



    echo -aoE '([a-zA-Z])1,5' file

    output
    My
    name
    is
    nick
    rock
    and
    i
    live
    by
    the
    sea
    shore.


    I'll get this instead



    My name is nick rock and i live by the sea shore






    share|improve this question














    marked as duplicate by Sergiy Kolodyazhnyy command-line
    Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Jun 1 at 0:07


    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:



      • How can I print multiline output on the same line?

        8 answers



      This is related to a question i asked in overflow, It remains unanswered so i though I'd try asking it in segments



      My objective is to return the special n function, If i were to run



      echo -e "My name is nnick rock and i nlive by the sea shore." > file


      Then when i cat that file you get something like this



      My name is
      nick rock and i
      live by the sea shore.


      What I'm looking to do is reverse the n return function, so when i echo the file with something like this



      echo -aoE '([a-zA-Z])1,5' file

      output
      My
      name
      is
      nick
      rock
      and
      i
      live
      by
      the
      sea
      shore.


      I'll get this instead



      My name is nick rock and i live by the sea shore






      share|improve this question















      This question already has an answer here:



      • How can I print multiline output on the same line?

        8 answers



      This is related to a question i asked in overflow, It remains unanswered so i though I'd try asking it in segments



      My objective is to return the special n function, If i were to run



      echo -e "My name is nnick rock and i nlive by the sea shore." > file


      Then when i cat that file you get something like this



      My name is
      nick rock and i
      live by the sea shore.


      What I'm looking to do is reverse the n return function, so when i echo the file with something like this



      echo -aoE '([a-zA-Z])1,5' file

      output
      My
      name
      is
      nick
      rock
      and
      i
      live
      by
      the
      sea
      shore.


      I'll get this instead



      My name is nick rock and i live by the sea shore




      This question already has an answer here:



      • How can I print multiline output on the same line?

        8 answers









      share|improve this question













      share|improve this question




      share|improve this question








      edited May 29 at 8:37









      muru

      128k19270460




      128k19270460










      asked May 29 at 8:28









      hello moto

      3851315




      3851315




      marked as duplicate by Sergiy Kolodyazhnyy command-line
      Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jun 1 at 0:07


      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 Sergiy Kolodyazhnyy command-line
      Users with the  command-line badge can single-handedly close command-line questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jun 1 at 0:07


      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.






















          4 Answers
          4






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          What you're looking for is



          $ tr 'n' ' ' < file
          My name is nick rock and i live by the sea shore.


          tr utility is for translating sets of characters, in this there's only one character n in SET1 and space in SET2. As for < file, that just redirects the file into program's stdin stream.



          But if for some reason you need a shell-only way, then this is sufficient:



          $ while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; done < file
          My name is nick rock and i live by the sea shore.





          share|improve this answer



























            up vote
            2
            down vote













            you can use this command line, it's an improvement of @Sergiv Kolodyazhnyy which print the n at the right place



            while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; printf "n" ; done < test.txt 


            (sorry to not be able to comment)






            share|improve this answer



























              up vote
              2
              down vote













              You can also echo unquoted command-substitution:



              echo $(<infile)





              share|improve this answer




















              • I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                – danzel
                May 29 at 11:26











              • .... which is how word spliting is happening here
                – Î±Ò“sнιη
                May 29 at 12:02


















              up vote
              1
              down vote













              Here are some options:




              1. using awk, with an unset record separator (aka 'paragraph mode') and the default field separator



                awk -vRS= '$1=$1 1' file
                My name is nick rock and i live by the sea shore.



              2. using xargs with no explicit command



                $ xargs < file
                My name is nick rock and i live by the sea shore.



              3. using fmt from GNU coreutils:



                $ fmt file
                My name is nick rock and i live by the sea shore.






              share|improve this answer



























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                1
                down vote



                accepted










                What you're looking for is



                $ tr 'n' ' ' < file
                My name is nick rock and i live by the sea shore.


                tr utility is for translating sets of characters, in this there's only one character n in SET1 and space in SET2. As for < file, that just redirects the file into program's stdin stream.



                But if for some reason you need a shell-only way, then this is sufficient:



                $ while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; done < file
                My name is nick rock and i live by the sea shore.





                share|improve this answer
























                  up vote
                  1
                  down vote



                  accepted










                  What you're looking for is



                  $ tr 'n' ' ' < file
                  My name is nick rock and i live by the sea shore.


                  tr utility is for translating sets of characters, in this there's only one character n in SET1 and space in SET2. As for < file, that just redirects the file into program's stdin stream.



                  But if for some reason you need a shell-only way, then this is sufficient:



                  $ while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; done < file
                  My name is nick rock and i live by the sea shore.





                  share|improve this answer






















                    up vote
                    1
                    down vote



                    accepted







                    up vote
                    1
                    down vote



                    accepted






                    What you're looking for is



                    $ tr 'n' ' ' < file
                    My name is nick rock and i live by the sea shore.


                    tr utility is for translating sets of characters, in this there's only one character n in SET1 and space in SET2. As for < file, that just redirects the file into program's stdin stream.



                    But if for some reason you need a shell-only way, then this is sufficient:



                    $ while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; done < file
                    My name is nick rock and i live by the sea shore.





                    share|improve this answer












                    What you're looking for is



                    $ tr 'n' ' ' < file
                    My name is nick rock and i live by the sea shore.


                    tr utility is for translating sets of characters, in this there's only one character n in SET1 and space in SET2. As for < file, that just redirects the file into program's stdin stream.



                    But if for some reason you need a shell-only way, then this is sufficient:



                    $ while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; done < file
                    My name is nick rock and i live by the sea shore.






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 29 at 8:33









                    Sergiy Kolodyazhnyy

                    63.9k9127274




                    63.9k9127274






















                        up vote
                        2
                        down vote













                        you can use this command line, it's an improvement of @Sergiv Kolodyazhnyy which print the n at the right place



                        while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; printf "n" ; done < test.txt 


                        (sorry to not be able to comment)






                        share|improve this answer
























                          up vote
                          2
                          down vote













                          you can use this command line, it's an improvement of @Sergiv Kolodyazhnyy which print the n at the right place



                          while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; printf "n" ; done < test.txt 


                          (sorry to not be able to comment)






                          share|improve this answer






















                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            you can use this command line, it's an improvement of @Sergiv Kolodyazhnyy which print the n at the right place



                            while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; printf "n" ; done < test.txt 


                            (sorry to not be able to comment)






                            share|improve this answer












                            you can use this command line, it's an improvement of @Sergiv Kolodyazhnyy which print the n at the right place



                            while IFS= read -r line || [ -n "$line" ]; do printf "%s " "$line" ; printf "n" ; done < test.txt 


                            (sorry to not be able to comment)







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 29 at 8:41









                            damadam

                            800216




                            800216




















                                up vote
                                2
                                down vote













                                You can also echo unquoted command-substitution:



                                echo $(<infile)





                                share|improve this answer




















                                • I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                                  – danzel
                                  May 29 at 11:26











                                • .... which is how word spliting is happening here
                                  – Î±Ò“sнιη
                                  May 29 at 12:02















                                up vote
                                2
                                down vote













                                You can also echo unquoted command-substitution:



                                echo $(<infile)





                                share|improve this answer




















                                • I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                                  – danzel
                                  May 29 at 11:26











                                • .... which is how word spliting is happening here
                                  – Î±Ò“sнιη
                                  May 29 at 12:02













                                up vote
                                2
                                down vote










                                up vote
                                2
                                down vote









                                You can also echo unquoted command-substitution:



                                echo $(<infile)





                                share|improve this answer












                                You can also echo unquoted command-substitution:



                                echo $(<infile)






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered May 29 at 11:08









                                αғsнιη

                                22.8k2191150




                                22.8k2191150











                                • I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                                  – danzel
                                  May 29 at 11:26











                                • .... which is how word spliting is happening here
                                  – Î±Ò“sнιη
                                  May 29 at 12:02

















                                • I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                                  – danzel
                                  May 29 at 11:26











                                • .... which is how word spliting is happening here
                                  – Î±Ò“sнιη
                                  May 29 at 12:02
















                                I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                                – danzel
                                May 29 at 11:26





                                I like this one, but one should be aware that this will replace every sequence of characters in $IFS (usually space,newline,tab) by one space character.
                                – danzel
                                May 29 at 11:26













                                .... which is how word spliting is happening here
                                – Î±Ò“sнιη
                                May 29 at 12:02





                                .... which is how word spliting is happening here
                                – Î±Ò“sнιη
                                May 29 at 12:02











                                up vote
                                1
                                down vote













                                Here are some options:




                                1. using awk, with an unset record separator (aka 'paragraph mode') and the default field separator



                                  awk -vRS= '$1=$1 1' file
                                  My name is nick rock and i live by the sea shore.



                                2. using xargs with no explicit command



                                  $ xargs < file
                                  My name is nick rock and i live by the sea shore.



                                3. using fmt from GNU coreutils:



                                  $ fmt file
                                  My name is nick rock and i live by the sea shore.






                                share|improve this answer
























                                  up vote
                                  1
                                  down vote













                                  Here are some options:




                                  1. using awk, with an unset record separator (aka 'paragraph mode') and the default field separator



                                    awk -vRS= '$1=$1 1' file
                                    My name is nick rock and i live by the sea shore.



                                  2. using xargs with no explicit command



                                    $ xargs < file
                                    My name is nick rock and i live by the sea shore.



                                  3. using fmt from GNU coreutils:



                                    $ fmt file
                                    My name is nick rock and i live by the sea shore.






                                  share|improve this answer






















                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    Here are some options:




                                    1. using awk, with an unset record separator (aka 'paragraph mode') and the default field separator



                                      awk -vRS= '$1=$1 1' file
                                      My name is nick rock and i live by the sea shore.



                                    2. using xargs with no explicit command



                                      $ xargs < file
                                      My name is nick rock and i live by the sea shore.



                                    3. using fmt from GNU coreutils:



                                      $ fmt file
                                      My name is nick rock and i live by the sea shore.






                                    share|improve this answer












                                    Here are some options:




                                    1. using awk, with an unset record separator (aka 'paragraph mode') and the default field separator



                                      awk -vRS= '$1=$1 1' file
                                      My name is nick rock and i live by the sea shore.



                                    2. using xargs with no explicit command



                                      $ xargs < file
                                      My name is nick rock and i live by the sea shore.



                                    3. using fmt from GNU coreutils:



                                      $ fmt file
                                      My name is nick rock and i live by the sea shore.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered May 29 at 10:49









                                    steeldriver

                                    62.1k1196163




                                    62.1k1196163












                                        Popular posts from this blog

                                        Which professions warranted travel in Medieval times?

                                        How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

                                        Trouble downloading packages list due to a “Hash sum mismatch” error