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
bash putty
New contributor
add a comment |
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
bash putty
New contributor
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
add a comment |
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
bash putty
New contributor
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
bash putty
New contributor
New contributor
edited 50 mins ago
New contributor
asked 2 hours ago
Asu
1234
1234
New contributor
New contributor
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
add a comment |
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
add a comment |
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.
add a comment |
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.)
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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.
add a comment |
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.
add a comment |
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.
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.
edited 45 mins ago
answered 52 mins ago
JoL
927310
927310
add a comment |
add a comment |
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.)
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
add a comment |
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.)
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
add a comment |
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.)
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.)
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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