If a string has a blank within it, can I still use tsort on the string?












2














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.










share|improve this question




















  • 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
















2














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.










share|improve this question




















  • 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














2












2








2







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.










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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














  • 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








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










1 Answer
1






active

oldest

votes


















5














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.)






share|improve this answer

















  • 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











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
});


}
});














draft saved

draft discarded


















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









5














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.)






share|improve this answer

















  • 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
















5














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.)






share|improve this answer

















  • 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














5












5








5






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.)






share|improve this answer












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.)







share|improve this answer












share|improve this answer



share|improve this answer










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














  • 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


















draft saved

draft discarded




















































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%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





















































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

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents