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.










share|improve this question




















  • 1




    What happened when you tried?
    – Jeff Schaller
    2 days ago










  • " I'm confused by your question"
    – Tim
    2 days ago










  • 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
    2 days ago






  • 1




    If I think a question is self clear without those hassles, I won't go that way.
    – Tim
    2 days ago















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.










share|improve this question




















  • 1




    What happened when you tried?
    – Jeff Schaller
    2 days ago










  • " I'm confused by your question"
    – Tim
    2 days ago










  • 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
    2 days ago






  • 1




    If I think a question is self clear without those hassles, I won't go that way.
    – Tim
    2 days ago













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.










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 2 days ago

























asked 2 days ago









Tim

1




1








  • 1




    What happened when you tried?
    – Jeff Schaller
    2 days ago










  • " I'm confused by your question"
    – Tim
    2 days ago










  • 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
    2 days ago






  • 1




    If I think a question is self clear without those hassles, I won't go that way.
    – Tim
    2 days ago














  • 1




    What happened when you tried?
    – Jeff Schaller
    2 days ago










  • " I'm confused by your question"
    – Tim
    2 days ago










  • 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
    2 days ago






  • 1




    If I think a question is self clear without those hassles, I won't go that way.
    – Tim
    2 days ago








1




1




What happened when you tried?
– Jeff Schaller
2 days ago




What happened when you tried?
– Jeff Schaller
2 days ago












" I'm confused by your question"
– Tim
2 days ago




" I'm confused by your question"
– Tim
2 days ago












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
2 days ago




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
2 days ago




1




1




If I think a question is self clear without those hassles, I won't go that way.
– Tim
2 days ago




If I think a question is self clear without those hassles, I won't go that way.
– Tim
2 days ago










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






share|improve this answer

















  • 1




    For single character encodings, tr is likely to be easier.
    – D. Ben Knoble
    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
    yesterday










  • @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
    yesterday











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


}
});














 

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








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






share|improve this answer

















  • 1




    For single character encodings, tr is likely to be easier.
    – D. Ben Knoble
    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
    yesterday










  • @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
    yesterday















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






share|improve this answer

















  • 1




    For single character encodings, tr is likely to be easier.
    – D. Ben Knoble
    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
    yesterday










  • @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
    yesterday













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






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 2 days ago









Filipe Brandenburger

6,1041625




6,1041625








  • 1




    For single character encodings, tr is likely to be easier.
    – D. Ben Knoble
    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
    yesterday










  • @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
    yesterday














  • 1




    For single character encodings, tr is likely to be easier.
    – D. Ben Knoble
    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
    yesterday










  • @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
    yesterday








1




1




For single character encodings, tr is likely to be easier.
– D. Ben Knoble
2 days ago




For single character encodings, tr is likely to be easier.
– D. Ben Knoble
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
yesterday




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
yesterday












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




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


















 

draft saved


draft discarded



















































 


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

Bundesstraße 106

Le Mesnil-Réaume

Ida-Boy-Ed-Garten