If a string has a blank within it, can I still use tsort on the string?
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 |
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 '18 at 16:28
" I'm confused by your question"
– Tim
Nov 17 '18 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 '18 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 '18 at 17:42
add a comment |
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 '18 at 16:31
asked Nov 17 '18 at 16:20
Tim
26.2k74246455
26.2k74246455
1
What happened when you tried?
– Jeff Schaller
Nov 17 '18 at 16:28
" I'm confused by your question"
– Tim
Nov 17 '18 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 '18 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 '18 at 17:42
add a comment |
1
What happened when you tried?
– Jeff Schaller
Nov 17 '18 at 16:28
" I'm confused by your question"
– Tim
Nov 17 '18 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 '18 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 '18 at 17:42
1
1
What happened when you tried?
– Jeff Schaller
Nov 17 '18 at 16:28
What happened when you tried?
– Jeff Schaller
Nov 17 '18 at 16:28
" I'm confused by your question"
– Tim
Nov 17 '18 at 16:40
" I'm confused by your question"
– Tim
Nov 17 '18 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 '18 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 '18 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 '18 at 17:42
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 '18 at 17:42
add a comment |
1 Answer
1
active
oldest
votes
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 '18 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
Nov 18 '18 at 13:28
@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...
– filbranden
Nov 18 '18 at 16:18
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%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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 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
Nov 18 '18 at 13:28
@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...
– filbranden
Nov 18 '18 at 16:18
add a comment |
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 '18 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
Nov 18 '18 at 13:28
@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...
– filbranden
Nov 18 '18 at 16:18
add a comment |
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 '18 at 16:43
filbranden
7,2452836
7,2452836
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 '18 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
Nov 18 '18 at 13:28
@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...
– filbranden
Nov 18 '18 at 16:18
add a comment |
1
For single character encodings,tr
is likely to be easier.
– D. Ben Knoble
Nov 17 '18 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
Nov 18 '18 at 13:28
@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...
– filbranden
Nov 18 '18 at 16:18
1
1
For single character encodings,
tr
is likely to be easier.– D. Ben Knoble
Nov 17 '18 at 19:21
For single character encodings,
tr
is likely to be easier.– D. Ben Knoble
Nov 17 '18 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
Nov 18 '18 at 13:28
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
Nov 18 '18 at 13:28
@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...
– filbranden
Nov 18 '18 at 16:18
@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...
– filbranden
Nov 18 '18 at 16:18
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.
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%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 '18 at 16:28
" I'm confused by your question"
– Tim
Nov 17 '18 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 '18 at 17:35
1
If I think a question is self clear without those hassles, I won't go that way.
– Tim
Nov 17 '18 at 17:42