show stdout containing n with line breaksRemove forced line breaks from fortune output while preserving them for the author lineEcho new line and string beginning tHow to launch a pipe as a persistent processcolor of echo with commandsAdd line breaks to Grep CommandsKeep all line breaks except the last one using awk
Visa National - No Exit Stamp From France on Return to the UK
What are good ways to improve as a writer other than writing courses?
How does The Fools Guild make its money?
How to use grep to search through the --help output?
Max Order of an Isogeny Class of Rational Elliptic Curves is 8?
Ex-contractor published company source code and secrets online
Best gun to modify into a monsterhunter weapon?
Drawing complex inscribed and circumscribed polygons in TikZ
Senior dev discreetly remoting in to computer and watching a coworker
A stranger from Norway wants to have money delivered to me
As a 16 year old, how can I keep my money safe from my mother?
Does the United States guarantee any unique freedoms?
(11 of 11: Meta) What is Pyramid Cult's All-Time Favorite?
Why are the inside diameters of some pipe larger than the stated size?
How do I calculate the difference in lens reach between a superzoom compact and a DSLR zoom lens?
Non-OR journals which regularly publish OR research
English - Acceptable use of parentheses in an author's name
Write an interpreter for *
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
Dereferencing a pointer in a 'for' loop initializer creates a segmentation fault
Performance of a branch and bound algorithm VS branch-cut-heuristics
show stdout containing n with line breaks
Word or idiom defining something barely functional
How many different ways are there to checkmate in the early game?
show stdout containing n with line breaks
Remove forced line breaks from fortune output while preserving them for the author lineEcho new line and string beginning tHow to launch a pipe as a persistent processcolor of echo with commandsAdd line breaks to Grep CommandsKeep all line breaks except the last one using awk
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
The output from an executable (cURL) contains n. How can such output be displayed with line breaks ?
Say "tCLn1523 memon" is the output from an executable, piping to printf does not show line breaks.
$
$ echo "tCLn1523 memon"
tCLn1523 memon
$
$ printf "tCLn1523 memon"
tCL
1523 memo
$
$ echo "tCLn1523 memon" | xargs -0 printf '%s'
tCLn1523 memon
$
$ echo "tCLn1523 memon" | awk ' printf "%s", $0
tCLn1523 memon
$
bash echo newlines
add a comment |
The output from an executable (cURL) contains n. How can such output be displayed with line breaks ?
Say "tCLn1523 memon" is the output from an executable, piping to printf does not show line breaks.
$
$ echo "tCLn1523 memon"
tCLn1523 memon
$
$ printf "tCLn1523 memon"
tCL
1523 memo
$
$ echo "tCLn1523 memon" | xargs -0 printf '%s'
tCLn1523 memon
$
$ echo "tCLn1523 memon" | awk ' printf "%s", $0
tCLn1523 memon
$
bash echo newlines
That is because echo does only interpret sequences as n if you use the switch -e.
– Janka
8 hours ago
@Janka: In this case OP actually wantsechoto not interpret the newlines as they are usingechoto simulate thecurloutput that needs to be interpreted.
– Jesse_b
8 hours ago
add a comment |
The output from an executable (cURL) contains n. How can such output be displayed with line breaks ?
Say "tCLn1523 memon" is the output from an executable, piping to printf does not show line breaks.
$
$ echo "tCLn1523 memon"
tCLn1523 memon
$
$ printf "tCLn1523 memon"
tCL
1523 memo
$
$ echo "tCLn1523 memon" | xargs -0 printf '%s'
tCLn1523 memon
$
$ echo "tCLn1523 memon" | awk ' printf "%s", $0
tCLn1523 memon
$
bash echo newlines
The output from an executable (cURL) contains n. How can such output be displayed with line breaks ?
Say "tCLn1523 memon" is the output from an executable, piping to printf does not show line breaks.
$
$ echo "tCLn1523 memon"
tCLn1523 memon
$
$ printf "tCLn1523 memon"
tCL
1523 memo
$
$ echo "tCLn1523 memon" | xargs -0 printf '%s'
tCLn1523 memon
$
$ echo "tCLn1523 memon" | awk ' printf "%s", $0
tCLn1523 memon
$
bash echo newlines
bash echo newlines
edited 8 hours ago
Kusalananda♦
159k18 gold badges313 silver badges500 bronze badges
159k18 gold badges313 silver badges500 bronze badges
asked 8 hours ago
SOUserSOUser
19510 bronze badges
19510 bronze badges
That is because echo does only interpret sequences as n if you use the switch -e.
– Janka
8 hours ago
@Janka: In this case OP actually wantsechoto not interpret the newlines as they are usingechoto simulate thecurloutput that needs to be interpreted.
– Jesse_b
8 hours ago
add a comment |
That is because echo does only interpret sequences as n if you use the switch -e.
– Janka
8 hours ago
@Janka: In this case OP actually wantsechoto not interpret the newlines as they are usingechoto simulate thecurloutput that needs to be interpreted.
– Jesse_b
8 hours ago
That is because echo does only interpret sequences as n if you use the switch -e.
– Janka
8 hours ago
That is because echo does only interpret sequences as n if you use the switch -e.
– Janka
8 hours ago
@Janka: In this case OP actually wants
echo to not interpret the newlines as they are using echo to simulate the curl output that needs to be interpreted.– Jesse_b
8 hours ago
@Janka: In this case OP actually wants
echo to not interpret the newlines as they are using echo to simulate the curl output that needs to be interpreted.– Jesse_b
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
%s does not interpret escape sequences. You need %b for that:
% echo 'tCLn1523 memon' | xargs -0 printf "%b"
tCL
1523 memo
%
1
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
You'll probably have to use the input as the format string, after replacing all%with%%
– muru
7 hours ago
add a comment |
You probably need to transform double-backslash to backslash as well, otherwise the input format would be ambiguous.
You can write a sed script to translate backslash-letter escapes. This script only translates the escape sequences that it recognizes and otherwise removes the backslash. I've put in support for newline and tab.
… | sed 's/\n/n/g; s/\t/ /; s/\(.)/1/g'
The whitespace in s/\t/ / is a tab character. GNU sed lets you write s/\t/t/.
If you also want octal escapes, use a more advanced tool such as Perl. You can make it parse all the escape sequences that it supports.
… | perl -pe 's/\([0-7]1,3|c.|[oxN][^]+|.)/""\$1""/eeg'
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%2f534881%2fshow-stdout-containing-n-with-line-breaks%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
%s does not interpret escape sequences. You need %b for that:
% echo 'tCLn1523 memon' | xargs -0 printf "%b"
tCL
1523 memo
%
1
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
You'll probably have to use the input as the format string, after replacing all%with%%
– muru
7 hours ago
add a comment |
%s does not interpret escape sequences. You need %b for that:
% echo 'tCLn1523 memon' | xargs -0 printf "%b"
tCL
1523 memo
%
1
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
You'll probably have to use the input as the format string, after replacing all%with%%
– muru
7 hours ago
add a comment |
%s does not interpret escape sequences. You need %b for that:
% echo 'tCLn1523 memon' | xargs -0 printf "%b"
tCL
1523 memo
%
%s does not interpret escape sequences. You need %b for that:
% echo 'tCLn1523 memon' | xargs -0 printf "%b"
tCL
1523 memo
%
answered 7 hours ago
murumuru
43.6k5 gold badges108 silver badges181 bronze badges
43.6k5 gold badges108 silver badges181 bronze badges
1
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
You'll probably have to use the input as the format string, after replacing all%with%%
– muru
7 hours ago
add a comment |
1
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
You'll probably have to use the input as the format string, after replacing all%with%%
– muru
7 hours ago
1
1
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Nice one! I still think command substitution would be better than xargs though, no?
– Jesse_b
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
Possibly. In either case the entire output ends up as an argument, and with command substitution the extra xargs step is avoided.
– muru
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
@muru Thanks for your solution ! I wonder how to make awk printf also work, given %b is not available ?
– SOUser
7 hours ago
You'll probably have to use the input as the format string, after replacing all
% with %%– muru
7 hours ago
You'll probably have to use the input as the format string, after replacing all
% with %%– muru
7 hours ago
add a comment |
You probably need to transform double-backslash to backslash as well, otherwise the input format would be ambiguous.
You can write a sed script to translate backslash-letter escapes. This script only translates the escape sequences that it recognizes and otherwise removes the backslash. I've put in support for newline and tab.
… | sed 's/\n/n/g; s/\t/ /; s/\(.)/1/g'
The whitespace in s/\t/ / is a tab character. GNU sed lets you write s/\t/t/.
If you also want octal escapes, use a more advanced tool such as Perl. You can make it parse all the escape sequences that it supports.
… | perl -pe 's/\([0-7]1,3|c.|[oxN][^]+|.)/""\$1""/eeg'
add a comment |
You probably need to transform double-backslash to backslash as well, otherwise the input format would be ambiguous.
You can write a sed script to translate backslash-letter escapes. This script only translates the escape sequences that it recognizes and otherwise removes the backslash. I've put in support for newline and tab.
… | sed 's/\n/n/g; s/\t/ /; s/\(.)/1/g'
The whitespace in s/\t/ / is a tab character. GNU sed lets you write s/\t/t/.
If you also want octal escapes, use a more advanced tool such as Perl. You can make it parse all the escape sequences that it supports.
… | perl -pe 's/\([0-7]1,3|c.|[oxN][^]+|.)/""\$1""/eeg'
add a comment |
You probably need to transform double-backslash to backslash as well, otherwise the input format would be ambiguous.
You can write a sed script to translate backslash-letter escapes. This script only translates the escape sequences that it recognizes and otherwise removes the backslash. I've put in support for newline and tab.
… | sed 's/\n/n/g; s/\t/ /; s/\(.)/1/g'
The whitespace in s/\t/ / is a tab character. GNU sed lets you write s/\t/t/.
If you also want octal escapes, use a more advanced tool such as Perl. You can make it parse all the escape sequences that it supports.
… | perl -pe 's/\([0-7]1,3|c.|[oxN][^]+|.)/""\$1""/eeg'
You probably need to transform double-backslash to backslash as well, otherwise the input format would be ambiguous.
You can write a sed script to translate backslash-letter escapes. This script only translates the escape sequences that it recognizes and otherwise removes the backslash. I've put in support for newline and tab.
… | sed 's/\n/n/g; s/\t/ /; s/\(.)/1/g'
The whitespace in s/\t/ / is a tab character. GNU sed lets you write s/\t/t/.
If you also want octal escapes, use a more advanced tool such as Perl. You can make it parse all the escape sequences that it supports.
… | perl -pe 's/\([0-7]1,3|c.|[oxN][^]+|.)/""\$1""/eeg'
answered 7 hours ago
GillesGilles
569k136 gold badges1171 silver badges1684 bronze badges
569k136 gold badges1171 silver badges1684 bronze badges
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%2f534881%2fshow-stdout-containing-n-with-line-breaks%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
That is because echo does only interpret sequences as n if you use the switch -e.
– Janka
8 hours ago
@Janka: In this case OP actually wants
echoto not interpret the newlines as they are usingechoto simulate thecurloutput that needs to be interpreted.– Jesse_b
8 hours ago