How to avoid printing a newline when seq completes?












5














To create a column header, looking like:



1234567890123456789


I (am trying to) use seq and echo:



seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9


However, seq outputs a newline after each run. How can I avoid that?










share|improve this question





























    5














    To create a column header, looking like:



    1234567890123456789


    I (am trying to) use seq and echo:



    seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9


    However, seq outputs a newline after each run. How can I avoid that?










    share|improve this question



























      5












      5








      5







      To create a column header, looking like:



      1234567890123456789


      I (am trying to) use seq and echo:



      seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9


      However, seq outputs a newline after each run. How can I avoid that?










      share|improve this question















      To create a column header, looking like:



      1234567890123456789


      I (am trying to) use seq and echo:



      seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9


      However, seq outputs a newline after each run. How can I avoid that?







      gnu seq






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago









      poige

      4,0211542




      4,0211542










      asked 8 hours ago









      GreenMatt

      22917




      22917






















          6 Answers
          6






          active

          oldest

          votes


















          9














          Assuming you just want to print 1234567890123456789, you can do it with:



          $ printf "%s" $(seq 1 9) $(seq 0 9)
          1234567890123456789$


          That won't have a trailing newline at all though, so maybe you prefer:



          $ printf "%s" $(seq 1 9) $(seq 0 9) $'n'
          1234567890123456789
          $


          A few simpler choices if you don't need to use seq:



          $ perl -le 'print 1..9,0,1..9'
          1234567890123456789
          $ printf "%s" {1..9} {0..9} $'n'
          1234567890123456789


          Since you mentioned portability, I recommend you use the perl approach, or if you are likely to encounter systems without perl, and yet need the same command to run in shells including bash, sh, dash, tcsh etc, try Kamil's approach.






          share|improve this answer























          • Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
            – GreenMatt
            7 hours ago






          • 1




            @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
            – terdon
            7 hours ago








          • 2




            @GreenMatt of course, if you need portability, you should also avoid using echo.
            – terdon
            7 hours ago










          • Perl? <shudder>
            – GreenMatt
            7 hours ago






          • 1




            @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
            – terdon
            6 hours ago



















          6














          You can remove newlines from any stream with tr -d 'n'. In your case



          (seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9) | tr -d 'n'


          While other answers may concentrate on modifying your original approach, this is the way that should just remove newline characters regardless of what is before |.






          share|improve this answer

















          • 1




            Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
            – terdon
            7 hours ago










          • Ah yes, I never think of tr.
            – GreenMatt
            7 hours ago










          • +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
            – poige
            1 hour ago












          • My take on this: unix.stackexchange.com/a/492380/6622
            – poige
            5 mins ago



















          3














          I assume you don't want just that particular string, but strings of incrementing digits with variable lengths. For that, it may be useful to be able to change the width by changing one number, instead of having to build it from multiple calls to seq.



          In Bash, you could use something like this (for a 19-long sequence):



          for ((i=1; i <= 19; i++)); do printf "%d" "$(( i % 10 ))"; done; echo


          This should work in a standard shell (and works in at least dash and busybox, anyway):



          i=1; while [ "$i" -le 19 ]; do printf "%d" "$(( i % 10 ))"; i=$((i+1)); done; echo





          share|improve this answer























          • +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
            – Charles Duffy
            6 hours ago



















          2














          Consider also:



          printf '%d' $(seq -w 1 1 99 | cut -c2)


          We generate the numbers 01..99, zero-padded (-w), then strip off the tens-place. Those ones-place numbers are then sent to printf to be printed individually.



          To get your desired output, use 19 instead:



          $ printf '%d' $(seq -w 1 1 19 | cut -c2)
          1234567890123456789





          share|improve this answer































            0














            I wonder why you don't just:



            echo 1234567890123456789


            And what's the point of printing just 19 columns instead of 20?



            If you want it repeated (by default: for the whole width of the terminal)



            chdr(){ c=${1:-$COLUMNS}; while [ "$c" -gt 0 ]; do printf '%.*s' "$c" 1234567890; c=$((c-10)); done; echo; }
            chdr 17
            12345678901234567
            chdr
            12345678901234567890123456789012345678901234567890123456789012345678901234567890


            Of course, that won't work in csh (huh).



            FYI: seq isn't portable (there's jot on *BSD, but it's quite different).






            share|improve this answer































              0














              When using tr to get rid of trailing new-line it's worth realising that it deletes all occurrences of the characters given in its -d option. Thus you can get it a bit more slim:



              (seq 1 9; echo 0; seq 1 9) | tr -d 'n'


              — even echo doesn't need to have -n anymore.



              And for completeness sake: BSD's version of seq when -s '' specified doesn't produce new-line on its exit.





              share





















                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',
                autoActivateHeartbeat: false,
                convertImagesToLinks: false,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: null,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                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%2f492315%2fhow-to-avoid-printing-a-newline-when-seq-completes%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                6 Answers
                6






                active

                oldest

                votes








                6 Answers
                6






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                9














                Assuming you just want to print 1234567890123456789, you can do it with:



                $ printf "%s" $(seq 1 9) $(seq 0 9)
                1234567890123456789$


                That won't have a trailing newline at all though, so maybe you prefer:



                $ printf "%s" $(seq 1 9) $(seq 0 9) $'n'
                1234567890123456789
                $


                A few simpler choices if you don't need to use seq:



                $ perl -le 'print 1..9,0,1..9'
                1234567890123456789
                $ printf "%s" {1..9} {0..9} $'n'
                1234567890123456789


                Since you mentioned portability, I recommend you use the perl approach, or if you are likely to encounter systems without perl, and yet need the same command to run in shells including bash, sh, dash, tcsh etc, try Kamil's approach.






                share|improve this answer























                • Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
                  – terdon
                  7 hours ago








                • 2




                  @GreenMatt of course, if you need portability, you should also avoid using echo.
                  – terdon
                  7 hours ago










                • Perl? <shudder>
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
                  – terdon
                  6 hours ago
















                9














                Assuming you just want to print 1234567890123456789, you can do it with:



                $ printf "%s" $(seq 1 9) $(seq 0 9)
                1234567890123456789$


                That won't have a trailing newline at all though, so maybe you prefer:



                $ printf "%s" $(seq 1 9) $(seq 0 9) $'n'
                1234567890123456789
                $


                A few simpler choices if you don't need to use seq:



                $ perl -le 'print 1..9,0,1..9'
                1234567890123456789
                $ printf "%s" {1..9} {0..9} $'n'
                1234567890123456789


                Since you mentioned portability, I recommend you use the perl approach, or if you are likely to encounter systems without perl, and yet need the same command to run in shells including bash, sh, dash, tcsh etc, try Kamil's approach.






                share|improve this answer























                • Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
                  – terdon
                  7 hours ago








                • 2




                  @GreenMatt of course, if you need portability, you should also avoid using echo.
                  – terdon
                  7 hours ago










                • Perl? <shudder>
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
                  – terdon
                  6 hours ago














                9












                9








                9






                Assuming you just want to print 1234567890123456789, you can do it with:



                $ printf "%s" $(seq 1 9) $(seq 0 9)
                1234567890123456789$


                That won't have a trailing newline at all though, so maybe you prefer:



                $ printf "%s" $(seq 1 9) $(seq 0 9) $'n'
                1234567890123456789
                $


                A few simpler choices if you don't need to use seq:



                $ perl -le 'print 1..9,0,1..9'
                1234567890123456789
                $ printf "%s" {1..9} {0..9} $'n'
                1234567890123456789


                Since you mentioned portability, I recommend you use the perl approach, or if you are likely to encounter systems without perl, and yet need the same command to run in shells including bash, sh, dash, tcsh etc, try Kamil's approach.






                share|improve this answer














                Assuming you just want to print 1234567890123456789, you can do it with:



                $ printf "%s" $(seq 1 9) $(seq 0 9)
                1234567890123456789$


                That won't have a trailing newline at all though, so maybe you prefer:



                $ printf "%s" $(seq 1 9) $(seq 0 9) $'n'
                1234567890123456789
                $


                A few simpler choices if you don't need to use seq:



                $ perl -le 'print 1..9,0,1..9'
                1234567890123456789
                $ printf "%s" {1..9} {0..9} $'n'
                1234567890123456789


                Since you mentioned portability, I recommend you use the perl approach, or if you are likely to encounter systems without perl, and yet need the same command to run in shells including bash, sh, dash, tcsh etc, try Kamil's approach.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 7 hours ago

























                answered 8 hours ago









                terdon

                128k31249423




                128k31249423












                • Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
                  – terdon
                  7 hours ago








                • 2




                  @GreenMatt of course, if you need portability, you should also avoid using echo.
                  – terdon
                  7 hours ago










                • Perl? <shudder>
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
                  – terdon
                  6 hours ago


















                • Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
                  – terdon
                  7 hours ago








                • 2




                  @GreenMatt of course, if you need portability, you should also avoid using echo.
                  – terdon
                  7 hours ago










                • Perl? <shudder>
                  – GreenMatt
                  7 hours ago






                • 1




                  @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
                  – terdon
                  6 hours ago
















                Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
                – GreenMatt
                7 hours ago




                Thanks. How portable is that? It worked under Bash. Under tcsh I got an "Illegal variable name" error. Under sh, the 'n' was displayed.
                – GreenMatt
                7 hours ago




                1




                1




                @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
                – terdon
                7 hours ago






                @GreenMatt ah, that depends. For extreme portability, you may as well just use the perl one which is shell-agnostic. The printf "%s" $(seq 1 9) $(seq 0 9) will work in any POSIX shell, including sh and dash, but the printf "%s" $(seq 1 9) $(seq 0 9) $'n' will fail in dash. Note that it does work in sh (or at least in bash running as sh, so in POSIX mode), I assume you're running Ubuntu or a simmilar system whose sh is actually dash. tcsh is a strange one and not even trying to be POSIX so don't expect any of the shell-based approaches to work there.
                – terdon
                7 hours ago






                2




                2




                @GreenMatt of course, if you need portability, you should also avoid using echo.
                – terdon
                7 hours ago




                @GreenMatt of course, if you need portability, you should also avoid using echo.
                – terdon
                7 hours ago












                Perl? <shudder>
                – GreenMatt
                7 hours ago




                Perl? <shudder>
                – GreenMatt
                7 hours ago




                1




                1




                @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
                – terdon
                6 hours ago




                @GreenMatt lol. Say what you like about Perl, you just can't beat it for text manipulation and it is extremely portable.
                – terdon
                6 hours ago













                6














                You can remove newlines from any stream with tr -d 'n'. In your case



                (seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9) | tr -d 'n'


                While other answers may concentrate on modifying your original approach, this is the way that should just remove newline characters regardless of what is before |.






                share|improve this answer

















                • 1




                  Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
                  – terdon
                  7 hours ago










                • Ah yes, I never think of tr.
                  – GreenMatt
                  7 hours ago










                • +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
                  – poige
                  1 hour ago












                • My take on this: unix.stackexchange.com/a/492380/6622
                  – poige
                  5 mins ago
















                6














                You can remove newlines from any stream with tr -d 'n'. In your case



                (seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9) | tr -d 'n'


                While other answers may concentrate on modifying your original approach, this is the way that should just remove newline characters regardless of what is before |.






                share|improve this answer

















                • 1




                  Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
                  – terdon
                  7 hours ago










                • Ah yes, I never think of tr.
                  – GreenMatt
                  7 hours ago










                • +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
                  – poige
                  1 hour ago












                • My take on this: unix.stackexchange.com/a/492380/6622
                  – poige
                  5 mins ago














                6












                6








                6






                You can remove newlines from any stream with tr -d 'n'. In your case



                (seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9) | tr -d 'n'


                While other answers may concentrate on modifying your original approach, this is the way that should just remove newline characters regardless of what is before |.






                share|improve this answer












                You can remove newlines from any stream with tr -d 'n'. In your case



                (seq -s '' 1 9 ; echo -n 0; seq -s '' 1 9) | tr -d 'n'


                While other answers may concentrate on modifying your original approach, this is the way that should just remove newline characters regardless of what is before |.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 7 hours ago









                Kamil Maciorowski

                1,2591625




                1,2591625








                • 1




                  Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
                  – terdon
                  7 hours ago










                • Ah yes, I never think of tr.
                  – GreenMatt
                  7 hours ago










                • +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
                  – poige
                  1 hour ago












                • My take on this: unix.stackexchange.com/a/492380/6622
                  – poige
                  5 mins ago














                • 1




                  Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
                  – terdon
                  7 hours ago










                • Ah yes, I never think of tr.
                  – GreenMatt
                  7 hours ago










                • +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
                  – poige
                  1 hour ago












                • My take on this: unix.stackexchange.com/a/492380/6622
                  – poige
                  5 mins ago








                1




                1




                Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
                – terdon
                7 hours ago




                Nice. This also has the benefit of being portable to most (all?) shells. I think the OP wants the final newline, so another option might be ( seq -s '' 1 9 ; echo -n 0 ; seq -s '' 1 9 ) | tr -d 'n' ; printf "n".
                – terdon
                7 hours ago












                Ah yes, I never think of tr.
                – GreenMatt
                7 hours ago




                Ah yes, I never think of tr.
                – GreenMatt
                7 hours ago












                +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
                – poige
                1 hour ago






                +1. Also, worth saying that BSD version of seq does treat -s '' more fully than GNU's — no newline is printed even when it exits (they q-n wouldn't arise at all there)
                – poige
                1 hour ago














                My take on this: unix.stackexchange.com/a/492380/6622
                – poige
                5 mins ago




                My take on this: unix.stackexchange.com/a/492380/6622
                – poige
                5 mins ago











                3














                I assume you don't want just that particular string, but strings of incrementing digits with variable lengths. For that, it may be useful to be able to change the width by changing one number, instead of having to build it from multiple calls to seq.



                In Bash, you could use something like this (for a 19-long sequence):



                for ((i=1; i <= 19; i++)); do printf "%d" "$(( i % 10 ))"; done; echo


                This should work in a standard shell (and works in at least dash and busybox, anyway):



                i=1; while [ "$i" -le 19 ]; do printf "%d" "$(( i % 10 ))"; i=$((i+1)); done; echo





                share|improve this answer























                • +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
                  – Charles Duffy
                  6 hours ago
















                3














                I assume you don't want just that particular string, but strings of incrementing digits with variable lengths. For that, it may be useful to be able to change the width by changing one number, instead of having to build it from multiple calls to seq.



                In Bash, you could use something like this (for a 19-long sequence):



                for ((i=1; i <= 19; i++)); do printf "%d" "$(( i % 10 ))"; done; echo


                This should work in a standard shell (and works in at least dash and busybox, anyway):



                i=1; while [ "$i" -le 19 ]; do printf "%d" "$(( i % 10 ))"; i=$((i+1)); done; echo





                share|improve this answer























                • +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
                  – Charles Duffy
                  6 hours ago














                3












                3








                3






                I assume you don't want just that particular string, but strings of incrementing digits with variable lengths. For that, it may be useful to be able to change the width by changing one number, instead of having to build it from multiple calls to seq.



                In Bash, you could use something like this (for a 19-long sequence):



                for ((i=1; i <= 19; i++)); do printf "%d" "$(( i % 10 ))"; done; echo


                This should work in a standard shell (and works in at least dash and busybox, anyway):



                i=1; while [ "$i" -le 19 ]; do printf "%d" "$(( i % 10 ))"; i=$((i+1)); done; echo





                share|improve this answer














                I assume you don't want just that particular string, but strings of incrementing digits with variable lengths. For that, it may be useful to be able to change the width by changing one number, instead of having to build it from multiple calls to seq.



                In Bash, you could use something like this (for a 19-long sequence):



                for ((i=1; i <= 19; i++)); do printf "%d" "$(( i % 10 ))"; done; echo


                This should work in a standard shell (and works in at least dash and busybox, anyway):



                i=1; while [ "$i" -le 19 ]; do printf "%d" "$(( i % 10 ))"; i=$((i+1)); done; echo






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 6 hours ago

























                answered 6 hours ago









                ilkkachu

                56.1k784155




                56.1k784155












                • +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
                  – Charles Duffy
                  6 hours ago


















                • +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
                  – Charles Duffy
                  6 hours ago
















                +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
                – Charles Duffy
                6 hours ago




                +1: The latter approach looks like everything it needs should be guaranteed to be available in any POSIX-y shell to me.
                – Charles Duffy
                6 hours ago











                2














                Consider also:



                printf '%d' $(seq -w 1 1 99 | cut -c2)


                We generate the numbers 01..99, zero-padded (-w), then strip off the tens-place. Those ones-place numbers are then sent to printf to be printed individually.



                To get your desired output, use 19 instead:



                $ printf '%d' $(seq -w 1 1 19 | cut -c2)
                1234567890123456789





                share|improve this answer




























                  2














                  Consider also:



                  printf '%d' $(seq -w 1 1 99 | cut -c2)


                  We generate the numbers 01..99, zero-padded (-w), then strip off the tens-place. Those ones-place numbers are then sent to printf to be printed individually.



                  To get your desired output, use 19 instead:



                  $ printf '%d' $(seq -w 1 1 19 | cut -c2)
                  1234567890123456789





                  share|improve this answer


























                    2












                    2








                    2






                    Consider also:



                    printf '%d' $(seq -w 1 1 99 | cut -c2)


                    We generate the numbers 01..99, zero-padded (-w), then strip off the tens-place. Those ones-place numbers are then sent to printf to be printed individually.



                    To get your desired output, use 19 instead:



                    $ printf '%d' $(seq -w 1 1 19 | cut -c2)
                    1234567890123456789





                    share|improve this answer














                    Consider also:



                    printf '%d' $(seq -w 1 1 99 | cut -c2)


                    We generate the numbers 01..99, zero-padded (-w), then strip off the tens-place. Those ones-place numbers are then sent to printf to be printed individually.



                    To get your desired output, use 19 instead:



                    $ printf '%d' $(seq -w 1 1 19 | cut -c2)
                    1234567890123456789






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 3 hours ago









                    JoL

                    999310




                    999310










                    answered 8 hours ago









                    Jeff Schaller

                    38.9k1053125




                    38.9k1053125























                        0














                        I wonder why you don't just:



                        echo 1234567890123456789


                        And what's the point of printing just 19 columns instead of 20?



                        If you want it repeated (by default: for the whole width of the terminal)



                        chdr(){ c=${1:-$COLUMNS}; while [ "$c" -gt 0 ]; do printf '%.*s' "$c" 1234567890; c=$((c-10)); done; echo; }
                        chdr 17
                        12345678901234567
                        chdr
                        12345678901234567890123456789012345678901234567890123456789012345678901234567890


                        Of course, that won't work in csh (huh).



                        FYI: seq isn't portable (there's jot on *BSD, but it's quite different).






                        share|improve this answer




























                          0














                          I wonder why you don't just:



                          echo 1234567890123456789


                          And what's the point of printing just 19 columns instead of 20?



                          If you want it repeated (by default: for the whole width of the terminal)



                          chdr(){ c=${1:-$COLUMNS}; while [ "$c" -gt 0 ]; do printf '%.*s' "$c" 1234567890; c=$((c-10)); done; echo; }
                          chdr 17
                          12345678901234567
                          chdr
                          12345678901234567890123456789012345678901234567890123456789012345678901234567890


                          Of course, that won't work in csh (huh).



                          FYI: seq isn't portable (there's jot on *BSD, but it's quite different).






                          share|improve this answer


























                            0












                            0








                            0






                            I wonder why you don't just:



                            echo 1234567890123456789


                            And what's the point of printing just 19 columns instead of 20?



                            If you want it repeated (by default: for the whole width of the terminal)



                            chdr(){ c=${1:-$COLUMNS}; while [ "$c" -gt 0 ]; do printf '%.*s' "$c" 1234567890; c=$((c-10)); done; echo; }
                            chdr 17
                            12345678901234567
                            chdr
                            12345678901234567890123456789012345678901234567890123456789012345678901234567890


                            Of course, that won't work in csh (huh).



                            FYI: seq isn't portable (there's jot on *BSD, but it's quite different).






                            share|improve this answer














                            I wonder why you don't just:



                            echo 1234567890123456789


                            And what's the point of printing just 19 columns instead of 20?



                            If you want it repeated (by default: for the whole width of the terminal)



                            chdr(){ c=${1:-$COLUMNS}; while [ "$c" -gt 0 ]; do printf '%.*s' "$c" 1234567890; c=$((c-10)); done; echo; }
                            chdr 17
                            12345678901234567
                            chdr
                            12345678901234567890123456789012345678901234567890123456789012345678901234567890


                            Of course, that won't work in csh (huh).



                            FYI: seq isn't portable (there's jot on *BSD, but it's quite different).







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 20 mins ago

























                            answered 45 mins ago









                            pizdelect

                            36716




                            36716























                                0














                                When using tr to get rid of trailing new-line it's worth realising that it deletes all occurrences of the characters given in its -d option. Thus you can get it a bit more slim:



                                (seq 1 9; echo 0; seq 1 9) | tr -d 'n'


                                — even echo doesn't need to have -n anymore.



                                And for completeness sake: BSD's version of seq when -s '' specified doesn't produce new-line on its exit.





                                share


























                                  0














                                  When using tr to get rid of trailing new-line it's worth realising that it deletes all occurrences of the characters given in its -d option. Thus you can get it a bit more slim:



                                  (seq 1 9; echo 0; seq 1 9) | tr -d 'n'


                                  — even echo doesn't need to have -n anymore.



                                  And for completeness sake: BSD's version of seq when -s '' specified doesn't produce new-line on its exit.





                                  share
























                                    0












                                    0








                                    0






                                    When using tr to get rid of trailing new-line it's worth realising that it deletes all occurrences of the characters given in its -d option. Thus you can get it a bit more slim:



                                    (seq 1 9; echo 0; seq 1 9) | tr -d 'n'


                                    — even echo doesn't need to have -n anymore.



                                    And for completeness sake: BSD's version of seq when -s '' specified doesn't produce new-line on its exit.





                                    share












                                    When using tr to get rid of trailing new-line it's worth realising that it deletes all occurrences of the characters given in its -d option. Thus you can get it a bit more slim:



                                    (seq 1 9; echo 0; seq 1 9) | tr -d 'n'


                                    — even echo doesn't need to have -n anymore.



                                    And for completeness sake: BSD's version of seq when -s '' specified doesn't produce new-line on its exit.






                                    share











                                    share


                                    share










                                    answered 6 mins ago









                                    poige

                                    4,0211542




                                    4,0211542






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f492315%2fhow-to-avoid-printing-a-newline-when-seq-completes%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        濃尾地震

                                        How to rewrite equation of hyperbola in standard form

                                        No ethernet ip address in my vocore2