Linux tr to convert vertical text to horizontalStream Media Content from Linux to PS3Can I unzip and merge sorted text files in a single operation?chrome freezes Ubuntu 13.04Find where is a shared library symbol defined on a live system / list all symbols exported on a systemWhich strategy suits best a user with a scientific background like me? (Linux Desktop, Dual Boot, Virtualization)/ (Fedora? Arch? Win?)Grub error: unknown filesystem. (all partitions are unknown)GNU/Linux OOM (out of memory) freezes - solution ideasHow to disable/enable the touchpad for the Lenovo Yoga 900 13ISK2Securely Piping String in Local Text File to Remote Command using SSHSecond Screen Recognised/Connected But Not Displaying - Ubuntu 18.04 / Arch Linux
My student in one course asks for paid tutoring in another course. Appropriate?
How useful is the GRE Exam?
How can caller ID be faked?
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
What is this plant I saw for sale at a Romanian farmer's market?
How to recover a single blank shot from a film camera
Boundaries and Buddhism
writing a function between sets vertically
How can I prevent a user from copying files on another hard drive?
What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?
How did Frodo know where the Bree village was?
Digital signature that is only verifiable by one specific person
Query nodes and attributes of parent ways
Fill the maze with a wall-following Snake until it gets stuck
Is it a bad idea to have a pen name with only an initial for a surname?
Basic power tool set for Home repair and simple projects
What is "dot" sign in •NO?
How can the US president give an order to a civilian?
cannot access to my session
Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?
How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?
Why do you need to heat the pan before heating the olive oil?
When is the phrase "j'ai bon" used?
Why swap space doesn't get filesystem check at boot time?
Linux tr to convert vertical text to horizontal
Stream Media Content from Linux to PS3Can I unzip and merge sorted text files in a single operation?chrome freezes Ubuntu 13.04Find where is a shared library symbol defined on a live system / list all symbols exported on a systemWhich strategy suits best a user with a scientific background like me? (Linux Desktop, Dual Boot, Virtualization)/ (Fedora? Arch? Win?)Grub error: unknown filesystem. (all partitions are unknown)GNU/Linux OOM (out of memory) freezes - solution ideasHow to disable/enable the touchpad for the Lenovo Yoga 900 13ISK2Securely Piping String in Local Text File to Remote Command using SSHSecond Screen Recognised/Connected But Not Displaying - Ubuntu 18.04 / Arch Linux
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I've been reading about https://stackoverflow.com/questions/39791042/convert-vertical-text-into-horizontal-in-shell
and wondering if tr
alone can be used to convert vertical text to horizontal.
user@linux:~$ seq 3
1
2
3
user@linux:~$
I've tried the following solution, it works but not perfect.
user@linux:~$ seq 3 | tr -d 'n'
123user@linux:~$
user@linux:~$
Would it be possible to used tr
alone to produce output like this?
Desired Output
user@linux:~$ seq 3 | tr command here
123
user@linux:~$
linux tr
add a comment |
I've been reading about https://stackoverflow.com/questions/39791042/convert-vertical-text-into-horizontal-in-shell
and wondering if tr
alone can be used to convert vertical text to horizontal.
user@linux:~$ seq 3
1
2
3
user@linux:~$
I've tried the following solution, it works but not perfect.
user@linux:~$ seq 3 | tr -d 'n'
123user@linux:~$
user@linux:~$
Would it be possible to used tr
alone to produce output like this?
Desired Output
user@linux:~$ seq 3 | tr command here
123
user@linux:~$
linux tr
1
tr -d 'n'
is finr for all piped and file-to-file operations. Don't be fooled by the tty output.
– Fiximan
May 31 at 12:28
1
@Fiximan no it's not. Otherwise the following would work as expected:seq 3 | tr -d 'n' | cat
. Notice the pipe tocat
here, which didn't add the newline as the OP wanted (and which POSIX text files are required to have).
– Ruslan
May 31 at 20:58
add a comment |
I've been reading about https://stackoverflow.com/questions/39791042/convert-vertical-text-into-horizontal-in-shell
and wondering if tr
alone can be used to convert vertical text to horizontal.
user@linux:~$ seq 3
1
2
3
user@linux:~$
I've tried the following solution, it works but not perfect.
user@linux:~$ seq 3 | tr -d 'n'
123user@linux:~$
user@linux:~$
Would it be possible to used tr
alone to produce output like this?
Desired Output
user@linux:~$ seq 3 | tr command here
123
user@linux:~$
linux tr
I've been reading about https://stackoverflow.com/questions/39791042/convert-vertical-text-into-horizontal-in-shell
and wondering if tr
alone can be used to convert vertical text to horizontal.
user@linux:~$ seq 3
1
2
3
user@linux:~$
I've tried the following solution, it works but not perfect.
user@linux:~$ seq 3 | tr -d 'n'
123user@linux:~$
user@linux:~$
Would it be possible to used tr
alone to produce output like this?
Desired Output
user@linux:~$ seq 3 | tr command here
123
user@linux:~$
linux tr
linux tr
asked May 31 at 12:01
SabrinaSabrina
333110
333110
1
tr -d 'n'
is finr for all piped and file-to-file operations. Don't be fooled by the tty output.
– Fiximan
May 31 at 12:28
1
@Fiximan no it's not. Otherwise the following would work as expected:seq 3 | tr -d 'n' | cat
. Notice the pipe tocat
here, which didn't add the newline as the OP wanted (and which POSIX text files are required to have).
– Ruslan
May 31 at 20:58
add a comment |
1
tr -d 'n'
is finr for all piped and file-to-file operations. Don't be fooled by the tty output.
– Fiximan
May 31 at 12:28
1
@Fiximan no it's not. Otherwise the following would work as expected:seq 3 | tr -d 'n' | cat
. Notice the pipe tocat
here, which didn't add the newline as the OP wanted (and which POSIX text files are required to have).
– Ruslan
May 31 at 20:58
1
1
tr -d 'n'
is finr for all piped and file-to-file operations. Don't be fooled by the tty output.– Fiximan
May 31 at 12:28
tr -d 'n'
is finr for all piped and file-to-file operations. Don't be fooled by the tty output.– Fiximan
May 31 at 12:28
1
1
@Fiximan no it's not. Otherwise the following would work as expected:
seq 3 | tr -d 'n' | cat
. Notice the pipe to cat
here, which didn't add the newline as the OP wanted (and which POSIX text files are required to have).– Ruslan
May 31 at 20:58
@Fiximan no it's not. Otherwise the following would work as expected:
seq 3 | tr -d 'n' | cat
. Notice the pipe to cat
here, which didn't add the newline as the OP wanted (and which POSIX text files are required to have).– Ruslan
May 31 at 20:58
add a comment |
6 Answers
6
active
oldest
votes
Choose whatever works for you.
$ seq 3 | paste -s -d ''
123
$ seq 3 | tr -d 'n';echo
123
$ seq 3 | awk 1 ORS='';echo
123
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
$ seq -s '' 3
123
This instructs seq
to use the empty string as separator for the numbers (rather than the default newline character).
Nice. Didn't know about this. What if the vertical text is saved in a file instead ofseq 3
?
– Sabrina
May 31 at 12:54
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
add a comment |
Try this,
seq 3 | paste -s -d ''
123
- -d, delimiters as null
- -s, print in serial instead of in parallel
So it's not possible to usetr
alone to solve this?
– Sabrina
May 31 at 12:09
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
A solution could be
echo $(seq 3 | tr -d 'n')
As you are removing all newlines with switch -d 'n'
you have to add the last one again with some sort of trick.
add a comment |
You could use two tr
commands and some shell features (a shell built-in, and a here-string or here-doc):
seq 3 | (tr -d 'n'; tr -s 'n' <<< "")
seq 3 | (tr -d 'n'; tr -s 'n' << EOF
EOF
)
You might as well usetr -s 'n' <<< ''
ortr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
add a comment |
Tried with below 2 methods
First method
command:
seq 3| perl -pne "s/n//g"
output
123
Second(Python)
!/usr/bin/python
import re
z=[]
import subprocess
k=open('o','r')
for i in k:
z.append(i.strip())
print "".join(z)
Note: Here o is the filename
output
@host-1-49 ~]# python o.py
123
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',
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
);
);
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%2f522145%2flinux-tr-to-convert-vertical-text-to-horizontal%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
Choose whatever works for you.
$ seq 3 | paste -s -d ''
123
$ seq 3 | tr -d 'n';echo
123
$ seq 3 | awk 1 ORS='';echo
123
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
Choose whatever works for you.
$ seq 3 | paste -s -d ''
123
$ seq 3 | tr -d 'n';echo
123
$ seq 3 | awk 1 ORS='';echo
123
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
Choose whatever works for you.
$ seq 3 | paste -s -d ''
123
$ seq 3 | tr -d 'n';echo
123
$ seq 3 | awk 1 ORS='';echo
123
Choose whatever works for you.
$ seq 3 | paste -s -d ''
123
$ seq 3 | tr -d 'n';echo
123
$ seq 3 | awk 1 ORS='';echo
123
edited May 31 at 22:38
jwodder
194111
194111
answered May 31 at 12:48
asktyagiasktyagi
5459
5459
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
Note that
paste -s -d ''
is not portable nor POSIX. The portable equivalent would be paste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
Note that
paste -s -d ''
is not portable nor POSIX. The portable equivalent would be paste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
$ seq -s '' 3
123
This instructs seq
to use the empty string as separator for the numbers (rather than the default newline character).
Nice. Didn't know about this. What if the vertical text is saved in a file instead ofseq 3
?
– Sabrina
May 31 at 12:54
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
add a comment |
$ seq -s '' 3
123
This instructs seq
to use the empty string as separator for the numbers (rather than the default newline character).
Nice. Didn't know about this. What if the vertical text is saved in a file instead ofseq 3
?
– Sabrina
May 31 at 12:54
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
add a comment |
$ seq -s '' 3
123
This instructs seq
to use the empty string as separator for the numbers (rather than the default newline character).
$ seq -s '' 3
123
This instructs seq
to use the empty string as separator for the numbers (rather than the default newline character).
answered May 31 at 12:39
Kusalananda♦Kusalananda
151k18290477
151k18290477
Nice. Didn't know about this. What if the vertical text is saved in a file instead ofseq 3
?
– Sabrina
May 31 at 12:54
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
add a comment |
Nice. Didn't know about this. What if the vertical text is saved in a file instead ofseq 3
?
– Sabrina
May 31 at 12:54
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
Nice. Didn't know about this. What if the vertical text is saved in a file instead of
seq 3
?– Sabrina
May 31 at 12:54
Nice. Didn't know about this. What if the vertical text is saved in a file instead of
seq 3
?– Sabrina
May 31 at 12:54
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
@Sabrina Then you would use any of the alternatives in asktyagi's answer.
– Kusalananda♦
May 31 at 13:03
add a comment |
Try this,
seq 3 | paste -s -d ''
123
- -d, delimiters as null
- -s, print in serial instead of in parallel
So it's not possible to usetr
alone to solve this?
– Sabrina
May 31 at 12:09
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
Try this,
seq 3 | paste -s -d ''
123
- -d, delimiters as null
- -s, print in serial instead of in parallel
So it's not possible to usetr
alone to solve this?
– Sabrina
May 31 at 12:09
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
Try this,
seq 3 | paste -s -d ''
123
- -d, delimiters as null
- -s, print in serial instead of in parallel
Try this,
seq 3 | paste -s -d ''
123
- -d, delimiters as null
- -s, print in serial instead of in parallel
answered May 31 at 12:06
msp9011msp9011
5,09044269
5,09044269
So it's not possible to usetr
alone to solve this?
– Sabrina
May 31 at 12:09
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
So it's not possible to usetr
alone to solve this?
– Sabrina
May 31 at 12:09
Note thatpaste -s -d ''
is not portable nor POSIX. The portable equivalent would bepaste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
So it's not possible to use
tr
alone to solve this?– Sabrina
May 31 at 12:09
So it's not possible to use
tr
alone to solve this?– Sabrina
May 31 at 12:09
Note that
paste -s -d ''
is not portable nor POSIX. The portable equivalent would be paste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
Note that
paste -s -d ''
is not portable nor POSIX. The portable equivalent would be paste -sd '' -
– Stéphane Chazelas
Jun 1 at 10:55
add a comment |
A solution could be
echo $(seq 3 | tr -d 'n')
As you are removing all newlines with switch -d 'n'
you have to add the last one again with some sort of trick.
add a comment |
A solution could be
echo $(seq 3 | tr -d 'n')
As you are removing all newlines with switch -d 'n'
you have to add the last one again with some sort of trick.
add a comment |
A solution could be
echo $(seq 3 | tr -d 'n')
As you are removing all newlines with switch -d 'n'
you have to add the last one again with some sort of trick.
A solution could be
echo $(seq 3 | tr -d 'n')
As you are removing all newlines with switch -d 'n'
you have to add the last one again with some sort of trick.
edited Jun 1 at 1:45
muru
39.6k595171
39.6k595171
answered May 31 at 12:21
Frank AutenriethFrank Autenrieth
212
212
add a comment |
add a comment |
You could use two tr
commands and some shell features (a shell built-in, and a here-string or here-doc):
seq 3 | (tr -d 'n'; tr -s 'n' <<< "")
seq 3 | (tr -d 'n'; tr -s 'n' << EOF
EOF
)
You might as well usetr -s 'n' <<< ''
ortr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
add a comment |
You could use two tr
commands and some shell features (a shell built-in, and a here-string or here-doc):
seq 3 | (tr -d 'n'; tr -s 'n' <<< "")
seq 3 | (tr -d 'n'; tr -s 'n' << EOF
EOF
)
You might as well usetr -s 'n' <<< ''
ortr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
add a comment |
You could use two tr
commands and some shell features (a shell built-in, and a here-string or here-doc):
seq 3 | (tr -d 'n'; tr -s 'n' <<< "")
seq 3 | (tr -d 'n'; tr -s 'n' << EOF
EOF
)
You could use two tr
commands and some shell features (a shell built-in, and a here-string or here-doc):
seq 3 | (tr -d 'n'; tr -s 'n' <<< "")
seq 3 | (tr -d 'n'; tr -s 'n' << EOF
EOF
)
edited Jun 1 at 11:05
answered May 31 at 19:01
Jeff Schaller♦Jeff Schaller
47k1167152
47k1167152
You might as well usetr -s 'n' <<< ''
ortr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
add a comment |
You might as well usetr -s 'n' <<< ''
ortr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
You might as well use
tr -s 'n' <<< ''
or tr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
You might as well use
tr -s 'n' <<< ''
or tr x y <<< ''
– Stéphane Chazelas
Jun 1 at 10:58
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
Good point, Stéphane; I got stuck initially trying to convert /dev/null or /dev/zero; I'll simplify it with your suggestion. Thank you!
– Jeff Schaller♦
Jun 1 at 11:02
add a comment |
Tried with below 2 methods
First method
command:
seq 3| perl -pne "s/n//g"
output
123
Second(Python)
!/usr/bin/python
import re
z=[]
import subprocess
k=open('o','r')
for i in k:
z.append(i.strip())
print "".join(z)
Note: Here o is the filename
output
@host-1-49 ~]# python o.py
123
add a comment |
Tried with below 2 methods
First method
command:
seq 3| perl -pne "s/n//g"
output
123
Second(Python)
!/usr/bin/python
import re
z=[]
import subprocess
k=open('o','r')
for i in k:
z.append(i.strip())
print "".join(z)
Note: Here o is the filename
output
@host-1-49 ~]# python o.py
123
add a comment |
Tried with below 2 methods
First method
command:
seq 3| perl -pne "s/n//g"
output
123
Second(Python)
!/usr/bin/python
import re
z=[]
import subprocess
k=open('o','r')
for i in k:
z.append(i.strip())
print "".join(z)
Note: Here o is the filename
output
@host-1-49 ~]# python o.py
123
Tried with below 2 methods
First method
command:
seq 3| perl -pne "s/n//g"
output
123
Second(Python)
!/usr/bin/python
import re
z=[]
import subprocess
k=open('o','r')
for i in k:
z.append(i.strip())
print "".join(z)
Note: Here o is the filename
output
@host-1-49 ~]# python o.py
123
answered Jun 1 at 8:54
Praveen Kumar BSPraveen Kumar BS
2,0962311
2,0962311
add a comment |
add a comment |
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.
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%2f522145%2flinux-tr-to-convert-vertical-text-to-horizontal%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
1
tr -d 'n'
is finr for all piped and file-to-file operations. Don't be fooled by the tty output.– Fiximan
May 31 at 12:28
1
@Fiximan no it's not. Otherwise the following would work as expected:
seq 3 | tr -d 'n' | cat
. Notice the pipe tocat
here, which didn't add the newline as the OP wanted (and which POSIX text files are required to have).– Ruslan
May 31 at 20:58