If a string has a blank within it, can I still use tsort on the string?
up vote
2
down vote
favorite
coreutils manual says
tsort reads its input as pairs of strings, separated by blanks, indicating a partial ordering.
If a string has a blank within it, according to the manual, I can't use tsort on it and other strings. How can I still use tsort on the string and other strings? Thanks.
coreutils tsort
add a comment |
up vote
2
down vote
favorite
coreutils manual says
tsort reads its input as pairs of strings, separated by blanks, indicating a partial ordering.
If a string has a blank within it, according to the manual, I can't use tsort on it and other strings. How can I still use tsort on the string and other strings? Thanks.
coreutils tsort
1
What happened when you tried?
– Jeff Schaller
Nov 17 at 16:28
" I'm confused by your question"
– Tim
Nov 17 at 16:40
I mean, the man page says that it delimits the inputs by blanks, and so I might be curious to try running it with various inputs, such asa b c
or"a b" c
and see what happened. If I was then confused about what happened, I'd propose a question that showed the documentation, my understanding of it, the inputs I tried, the output I got, and what output I expected. That's why I have downvoted this question. Does that clarify my "what happened when you tried?" question?
– Jeff Schaller
Nov 17 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 at 17:42
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
coreutils manual says
tsort reads its input as pairs of strings, separated by blanks, indicating a partial ordering.
If a string has a blank within it, according to the manual, I can't use tsort on it and other strings. How can I still use tsort on the string and other strings? Thanks.
coreutils tsort
coreutils manual says
tsort reads its input as pairs of strings, separated by blanks, indicating a partial ordering.
If a string has a blank within it, according to the manual, I can't use tsort on it and other strings. How can I still use tsort on the string and other strings? Thanks.
coreutils tsort
coreutils tsort
edited Nov 17 at 16:31
asked Nov 17 at 16:20
Tim
1
1
1
What happened when you tried?
– Jeff Schaller
Nov 17 at 16:28
" I'm confused by your question"
– Tim
Nov 17 at 16:40
I mean, the man page says that it delimits the inputs by blanks, and so I might be curious to try running it with various inputs, such asa b c
or"a b" c
and see what happened. If I was then confused about what happened, I'd propose a question that showed the documentation, my understanding of it, the inputs I tried, the output I got, and what output I expected. That's why I have downvoted this question. Does that clarify my "what happened when you tried?" question?
– Jeff Schaller
Nov 17 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 at 17:42
add a comment |
1
What happened when you tried?
– Jeff Schaller
Nov 17 at 16:28
" I'm confused by your question"
– Tim
Nov 17 at 16:40
I mean, the man page says that it delimits the inputs by blanks, and so I might be curious to try running it with various inputs, such asa b c
or"a b" c
and see what happened. If I was then confused about what happened, I'd propose a question that showed the documentation, my understanding of it, the inputs I tried, the output I got, and what output I expected. That's why I have downvoted this question. Does that clarify my "what happened when you tried?" question?
– Jeff Schaller
Nov 17 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 at 17:42
1
1
What happened when you tried?
– Jeff Schaller
Nov 17 at 16:28
What happened when you tried?
– Jeff Schaller
Nov 17 at 16:28
" I'm confused by your question"
– Tim
Nov 17 at 16:40
" I'm confused by your question"
– Tim
Nov 17 at 16:40
I mean, the man page says that it delimits the inputs by blanks, and so I might be curious to try running it with various inputs, such as
a b c
or "a b" c
and see what happened. If I was then confused about what happened, I'd propose a question that showed the documentation, my understanding of it, the inputs I tried, the output I got, and what output I expected. That's why I have downvoted this question. Does that clarify my "what happened when you tried?" question?– Jeff Schaller
Nov 17 at 17:35
I mean, the man page says that it delimits the inputs by blanks, and so I might be curious to try running it with various inputs, such as
a b c
or "a b" c
and see what happened. If I was then confused about what happened, I'd propose a question that showed the documentation, my understanding of it, the inputs I tried, the output I got, and what output I expected. That's why I have downvoted this question. Does that clarify my "what happened when you tried?" question?– Jeff Schaller
Nov 17 at 17:35
1
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 at 17:42
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 at 17:42
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
You can't use tsort directly if some of your input strings contain whitespace.
You can check the source, you'll see the delimiters are hardcoded to space, tab and newline and there's no option to change them.
If you want to use tsort on a data set where words may contain whitespace, my recommendation would be to pre-process the data set to encode whitespace as a non-blank character (or sequence of non-blank characters), then run tsort on it and finally post-process the final output to decode it back into the original whitespace.
You can probably use sed
for the pre- and post-processing steps. Which character to use to encode whitespace depends on your data set, if there are other characters that are invalid (e.g. #
or @
, $
or ), maybe you can simply use them directly. Otherwise, you might want to consider a two character encoding (e.g. encode space as
s
) and include a way to encode the quoting character itself (e.g. \
to encode a single backspace.)
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 at 19:21
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
You can't use tsort directly if some of your input strings contain whitespace.
You can check the source, you'll see the delimiters are hardcoded to space, tab and newline and there's no option to change them.
If you want to use tsort on a data set where words may contain whitespace, my recommendation would be to pre-process the data set to encode whitespace as a non-blank character (or sequence of non-blank characters), then run tsort on it and finally post-process the final output to decode it back into the original whitespace.
You can probably use sed
for the pre- and post-processing steps. Which character to use to encode whitespace depends on your data set, if there are other characters that are invalid (e.g. #
or @
, $
or ), maybe you can simply use them directly. Otherwise, you might want to consider a two character encoding (e.g. encode space as
s
) and include a way to encode the quoting character itself (e.g. \
to encode a single backspace.)
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 at 19:21
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
add a comment |
up vote
5
down vote
accepted
You can't use tsort directly if some of your input strings contain whitespace.
You can check the source, you'll see the delimiters are hardcoded to space, tab and newline and there's no option to change them.
If you want to use tsort on a data set where words may contain whitespace, my recommendation would be to pre-process the data set to encode whitespace as a non-blank character (or sequence of non-blank characters), then run tsort on it and finally post-process the final output to decode it back into the original whitespace.
You can probably use sed
for the pre- and post-processing steps. Which character to use to encode whitespace depends on your data set, if there are other characters that are invalid (e.g. #
or @
, $
or ), maybe you can simply use them directly. Otherwise, you might want to consider a two character encoding (e.g. encode space as
s
) and include a way to encode the quoting character itself (e.g. \
to encode a single backspace.)
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 at 19:21
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
You can't use tsort directly if some of your input strings contain whitespace.
You can check the source, you'll see the delimiters are hardcoded to space, tab and newline and there's no option to change them.
If you want to use tsort on a data set where words may contain whitespace, my recommendation would be to pre-process the data set to encode whitespace as a non-blank character (or sequence of non-blank characters), then run tsort on it and finally post-process the final output to decode it back into the original whitespace.
You can probably use sed
for the pre- and post-processing steps. Which character to use to encode whitespace depends on your data set, if there are other characters that are invalid (e.g. #
or @
, $
or ), maybe you can simply use them directly. Otherwise, you might want to consider a two character encoding (e.g. encode space as
s
) and include a way to encode the quoting character itself (e.g. \
to encode a single backspace.)
You can't use tsort directly if some of your input strings contain whitespace.
You can check the source, you'll see the delimiters are hardcoded to space, tab and newline and there's no option to change them.
If you want to use tsort on a data set where words may contain whitespace, my recommendation would be to pre-process the data set to encode whitespace as a non-blank character (or sequence of non-blank characters), then run tsort on it and finally post-process the final output to decode it back into the original whitespace.
You can probably use sed
for the pre- and post-processing steps. Which character to use to encode whitespace depends on your data set, if there are other characters that are invalid (e.g. #
or @
, $
or ), maybe you can simply use them directly. Otherwise, you might want to consider a two character encoding (e.g. encode space as
s
) and include a way to encode the quoting character itself (e.g. \
to encode a single backspace.)
answered Nov 17 at 16:43
Filipe Brandenburger
6,1141625
6,1141625
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 at 19:21
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
add a comment |
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 at 19:21
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
1
1
For single character encodings,
tr
is likely to be easier.– D. Ben Knoble
Nov 17 at 19:21
For single character encodings,
tr
is likely to be easier.– D. Ben Knoble
Nov 17 at 19:21
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
Thanks. Filipe and @D.BenKnoble: if a string has a blank within it, and the string separator is a blank, can you "pre-process the data set to encode whitespace as a non-blank character" using some program without manual distinguish a blank between within-a-string and separating-two-strings cases?
– Tim
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
@Tim It depends on your specific case... If you have one entry per line (one pair using two consecutive lines) then it's safe to replace spaces with another character, leaving newlines unchanged... Without knowing the specifics of what you're trying to accomplish, it's hard to say whether you can automatically distinguish the cases after assembling the file, or if you need to handle them beforehand...
– Filipe Brandenburger
2 days ago
add a comment |
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%2f482360%2fif-a-string-has-a-blank-within-it-can-i-still-use-tsort-on-the-string%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
What happened when you tried?
– Jeff Schaller
Nov 17 at 16:28
" I'm confused by your question"
– Tim
Nov 17 at 16:40
I mean, the man page says that it delimits the inputs by blanks, and so I might be curious to try running it with various inputs, such as
a b c
or"a b" c
and see what happened. If I was then confused about what happened, I'd propose a question that showed the documentation, my understanding of it, the inputs I tried, the output I got, and what output I expected. That's why I have downvoted this question. Does that clarify my "what happened when you tried?" question?– Jeff Schaller
Nov 17 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 at 17:42