How to print strings separated by TAB in bash?











up vote
4
down vote

favorite












I am trying to print two string separated by a TAB.
I have tried:



echo -e 'footbar'
printf '%st%sn' foo bar


Both of them print:



foo     bar


Where the whitespace between the two is actually 5 spaces (as per selecting the output with mouse in Putty).



I have also tried using CTRL+V and pressing TAB when typing the command, with the same result.



What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?



And the secondary question: why is bash expanding tabs into spaces?



Update:
Apparently, this is a problem of Putty:
https://superuser.com/questions/656838/how-to-make-putty-display-tabs-within-a-file-instead-of-changing-them-to-spaces










share|improve this question









New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3




    Related: Output tab character on terminal window
    – steeldriver
    2 hours ago










  • Why just not escape it? printf '%s\t%sn' foo bar
    – Valentin Bajrami
    1 hour ago










  • @steeldriver Thanks that's very similar to what I need, but ultimately there isn't a solution...
    – Asu
    1 hour ago















up vote
4
down vote

favorite












I am trying to print two string separated by a TAB.
I have tried:



echo -e 'footbar'
printf '%st%sn' foo bar


Both of them print:



foo     bar


Where the whitespace between the two is actually 5 spaces (as per selecting the output with mouse in Putty).



I have also tried using CTRL+V and pressing TAB when typing the command, with the same result.



What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?



And the secondary question: why is bash expanding tabs into spaces?



Update:
Apparently, this is a problem of Putty:
https://superuser.com/questions/656838/how-to-make-putty-display-tabs-within-a-file-instead-of-changing-them-to-spaces










share|improve this question









New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 3




    Related: Output tab character on terminal window
    – steeldriver
    2 hours ago










  • Why just not escape it? printf '%s\t%sn' foo bar
    – Valentin Bajrami
    1 hour ago










  • @steeldriver Thanks that's very similar to what I need, but ultimately there isn't a solution...
    – Asu
    1 hour ago













up vote
4
down vote

favorite









up vote
4
down vote

favorite











I am trying to print two string separated by a TAB.
I have tried:



echo -e 'footbar'
printf '%st%sn' foo bar


Both of them print:



foo     bar


Where the whitespace between the two is actually 5 spaces (as per selecting the output with mouse in Putty).



I have also tried using CTRL+V and pressing TAB when typing the command, with the same result.



What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?



And the secondary question: why is bash expanding tabs into spaces?



Update:
Apparently, this is a problem of Putty:
https://superuser.com/questions/656838/how-to-make-putty-display-tabs-within-a-file-instead-of-changing-them-to-spaces










share|improve this question









New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to print two string separated by a TAB.
I have tried:



echo -e 'footbar'
printf '%st%sn' foo bar


Both of them print:



foo     bar


Where the whitespace between the two is actually 5 spaces (as per selecting the output with mouse in Putty).



I have also tried using CTRL+V and pressing TAB when typing the command, with the same result.



What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?



And the secondary question: why is bash expanding tabs into spaces?



Update:
Apparently, this is a problem of Putty:
https://superuser.com/questions/656838/how-to-make-putty-display-tabs-within-a-file-instead-of-changing-them-to-spaces







bash putty






share|improve this question









New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 50 mins ago





















New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









Asu

1234




1234




New contributor




Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Asu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 3




    Related: Output tab character on terminal window
    – steeldriver
    2 hours ago










  • Why just not escape it? printf '%s\t%sn' foo bar
    – Valentin Bajrami
    1 hour ago










  • @steeldriver Thanks that's very similar to what I need, but ultimately there isn't a solution...
    – Asu
    1 hour ago














  • 3




    Related: Output tab character on terminal window
    – steeldriver
    2 hours ago










  • Why just not escape it? printf '%s\t%sn' foo bar
    – Valentin Bajrami
    1 hour ago










  • @steeldriver Thanks that's very similar to what I need, but ultimately there isn't a solution...
    – Asu
    1 hour ago








3




3




Related: Output tab character on terminal window
– steeldriver
2 hours ago




Related: Output tab character on terminal window
– steeldriver
2 hours ago












Why just not escape it? printf '%s\t%sn' foo bar
– Valentin Bajrami
1 hour ago




Why just not escape it? printf '%s\t%sn' foo bar
– Valentin Bajrami
1 hour ago












@steeldriver Thanks that's very similar to what I need, but ultimately there isn't a solution...
– Asu
1 hour ago




@steeldriver Thanks that's very similar to what I need, but ultimately there isn't a solution...
– Asu
1 hour ago










2 Answers
2






active

oldest

votes

















up vote
3
down vote



accepted










Like ikkachu said, this isn't an issue with bash, but with the terminal emulator which converts tabs to spaces on output.



Checking different terminals, putty, xterm, and konsole convert tabs to spaces, while urxvt and gnome-terminal do not. So, another solution is to switch terminals.






share|improve this answer






























    up vote
    5
    down vote














    the whitespace between the two is actually 5 spaces.




    No, it's not. Not in the output of echo or printf.



    $ echo -e 'footbar' | od -c
    0000000 f o o t b a r n
    0000010



    What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?




    This is a different issue. It's not about the shell but the terminal emulator, which converts the tabs to spaces on output. Most, if not all of them do that, though I suppose it would be possible for a terminal to remember it was a tab to begin with, and let you copy it as-is.



    It may be easier to redirect the output with tabs to a file, and copy it from there, or to use unexpand on the output to convert spaces to tabs. (Though it also can't know what whitespace was tabs to begin with, and will convert all of it to tabs, if possible.)






    share|improve this answer





















    • I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
      – Asu
      1 hour ago






    • 1




      @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
      – JoL
      1 hour ago












    • @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
      – Asu
      59 mins ago











    Your Answer








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

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

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: 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
    });


    }
    });






    Asu is a new contributor. Be nice, and check out our Code of Conduct.










    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489150%2fhow-to-print-strings-separated-by-tab-in-bash%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    Like ikkachu said, this isn't an issue with bash, but with the terminal emulator which converts tabs to spaces on output.



    Checking different terminals, putty, xterm, and konsole convert tabs to spaces, while urxvt and gnome-terminal do not. So, another solution is to switch terminals.






    share|improve this answer



























      up vote
      3
      down vote



      accepted










      Like ikkachu said, this isn't an issue with bash, but with the terminal emulator which converts tabs to spaces on output.



      Checking different terminals, putty, xterm, and konsole convert tabs to spaces, while urxvt and gnome-terminal do not. So, another solution is to switch terminals.






      share|improve this answer

























        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        Like ikkachu said, this isn't an issue with bash, but with the terminal emulator which converts tabs to spaces on output.



        Checking different terminals, putty, xterm, and konsole convert tabs to spaces, while urxvt and gnome-terminal do not. So, another solution is to switch terminals.






        share|improve this answer














        Like ikkachu said, this isn't an issue with bash, but with the terminal emulator which converts tabs to spaces on output.



        Checking different terminals, putty, xterm, and konsole convert tabs to spaces, while urxvt and gnome-terminal do not. So, another solution is to switch terminals.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 45 mins ago

























        answered 52 mins ago









        JoL

        927310




        927310
























            up vote
            5
            down vote














            the whitespace between the two is actually 5 spaces.




            No, it's not. Not in the output of echo or printf.



            $ echo -e 'footbar' | od -c
            0000000 f o o t b a r n
            0000010



            What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?




            This is a different issue. It's not about the shell but the terminal emulator, which converts the tabs to spaces on output. Most, if not all of them do that, though I suppose it would be possible for a terminal to remember it was a tab to begin with, and let you copy it as-is.



            It may be easier to redirect the output with tabs to a file, and copy it from there, or to use unexpand on the output to convert spaces to tabs. (Though it also can't know what whitespace was tabs to begin with, and will convert all of it to tabs, if possible.)






            share|improve this answer





















            • I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
              – Asu
              1 hour ago






            • 1




              @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
              – JoL
              1 hour ago












            • @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
              – Asu
              59 mins ago















            up vote
            5
            down vote














            the whitespace between the two is actually 5 spaces.




            No, it's not. Not in the output of echo or printf.



            $ echo -e 'footbar' | od -c
            0000000 f o o t b a r n
            0000010



            What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?




            This is a different issue. It's not about the shell but the terminal emulator, which converts the tabs to spaces on output. Most, if not all of them do that, though I suppose it would be possible for a terminal to remember it was a tab to begin with, and let you copy it as-is.



            It may be easier to redirect the output with tabs to a file, and copy it from there, or to use unexpand on the output to convert spaces to tabs. (Though it also can't know what whitespace was tabs to begin with, and will convert all of it to tabs, if possible.)






            share|improve this answer





















            • I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
              – Asu
              1 hour ago






            • 1




              @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
              – JoL
              1 hour ago












            • @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
              – Asu
              59 mins ago













            up vote
            5
            down vote










            up vote
            5
            down vote










            the whitespace between the two is actually 5 spaces.




            No, it's not. Not in the output of echo or printf.



            $ echo -e 'footbar' | od -c
            0000000 f o o t b a r n
            0000010



            What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?




            This is a different issue. It's not about the shell but the terminal emulator, which converts the tabs to spaces on output. Most, if not all of them do that, though I suppose it would be possible for a terminal to remember it was a tab to begin with, and let you copy it as-is.



            It may be easier to redirect the output with tabs to a file, and copy it from there, or to use unexpand on the output to convert spaces to tabs. (Though it also can't know what whitespace was tabs to begin with, and will convert all of it to tabs, if possible.)






            share|improve this answer













            the whitespace between the two is actually 5 spaces.




            No, it's not. Not in the output of echo or printf.



            $ echo -e 'footbar' | od -c
            0000000 f o o t b a r n
            0000010



            What is the correct way to force tab being printed as tab, so I can select the output and copy it to somewhere else, with tabs?




            This is a different issue. It's not about the shell but the terminal emulator, which converts the tabs to spaces on output. Most, if not all of them do that, though I suppose it would be possible for a terminal to remember it was a tab to begin with, and let you copy it as-is.



            It may be easier to redirect the output with tabs to a file, and copy it from there, or to use unexpand on the output to convert spaces to tabs. (Though it also can't know what whitespace was tabs to begin with, and will convert all of it to tabs, if possible.)







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 2 hours ago









            ilkkachu

            54.8k782148




            54.8k782148












            • I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
              – Asu
              1 hour ago






            • 1




              @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
              – JoL
              1 hour ago












            • @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
              – Asu
              59 mins ago


















            • I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
              – Asu
              1 hour ago






            • 1




              @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
              – JoL
              1 hour ago












            • @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
              – Asu
              59 mins ago
















            I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
            – Asu
            1 hour ago




            I meant that when I try to select the output, it is being treated as 5 spaces. Thanks for the 'od -c' to verify the contents of the command output.
            – Asu
            1 hour ago




            1




            1




            @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
            – JoL
            1 hour ago






            @Asu I think he understands that. His solution is to get the output via other means since the terminal emulator is not guaranteed to leave tabs as tabs when you select them in the window. However, I just checked and while putty, xterm, and konsole convert tabs to spaces, urxvt and gnome-terminal do not. So, another solution is to switch terminals.
            – JoL
            1 hour ago














            @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
            – Asu
            59 mins ago




            @JoL Yes, that's the conclusion I just came to a minute ago, and I think it would be the accepted answer if somebody cares to post it as such...
            – Asu
            59 mins ago










            Asu is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            Asu is a new contributor. Be nice, and check out our Code of Conduct.













            Asu is a new contributor. Be nice, and check out our Code of Conduct.












            Asu is a new contributor. Be nice, and check out our Code of Conduct.
















            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%2f489150%2fhow-to-print-strings-separated-by-tab-in-bash%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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

             ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕