How can I use sed to edit bash debug output? (bash -x)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












#!/bin/bash -x
echo This is a script that has debugging turned on


This script outputs



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on


I want to get rid of these +'s by deleting them or replacing them. I expected sed could fix my problem (sed 's/^++//g') -- But this approach doesn't affect the debug output lines.



With some more experimenting, I discovered that the debug output seems to be getting written to stderr (inferred this with the command ./test.sh 2>/dev/null which the output then excludes the debug lines)



With this new information, I would expect this to work
./test.sh 2>&1 | sed 's/^++//g'



But, alas, I still get the same undesired output:



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on









share|improve this question







New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2




    Why are you working so hard to undo what -x has added? Why not just remove the -x?
    – Jeff Schaller
    8 mins ago














up vote
0
down vote

favorite












#!/bin/bash -x
echo This is a script that has debugging turned on


This script outputs



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on


I want to get rid of these +'s by deleting them or replacing them. I expected sed could fix my problem (sed 's/^++//g') -- But this approach doesn't affect the debug output lines.



With some more experimenting, I discovered that the debug output seems to be getting written to stderr (inferred this with the command ./test.sh 2>/dev/null which the output then excludes the debug lines)



With this new information, I would expect this to work
./test.sh 2>&1 | sed 's/^++//g'



But, alas, I still get the same undesired output:



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on









share|improve this question







New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2




    Why are you working so hard to undo what -x has added? Why not just remove the -x?
    – Jeff Schaller
    8 mins ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











#!/bin/bash -x
echo This is a script that has debugging turned on


This script outputs



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on


I want to get rid of these +'s by deleting them or replacing them. I expected sed could fix my problem (sed 's/^++//g') -- But this approach doesn't affect the debug output lines.



With some more experimenting, I discovered that the debug output seems to be getting written to stderr (inferred this with the command ./test.sh 2>/dev/null which the output then excludes the debug lines)



With this new information, I would expect this to work
./test.sh 2>&1 | sed 's/^++//g'



But, alas, I still get the same undesired output:



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on









share|improve this question







New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











#!/bin/bash -x
echo This is a script that has debugging turned on


This script outputs



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on


I want to get rid of these +'s by deleting them or replacing them. I expected sed could fix my problem (sed 's/^++//g') -- But this approach doesn't affect the debug output lines.



With some more experimenting, I discovered that the debug output seems to be getting written to stderr (inferred this with the command ./test.sh 2>/dev/null which the output then excludes the debug lines)



With this new information, I would expect this to work
./test.sh 2>&1 | sed 's/^++//g'



But, alas, I still get the same undesired output:



+ echo This is a script that has debugging turned on
This is a script that has debugging turned on






bash sed scripting stderr






share|improve this question







New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 16 mins ago









aitee

1




1




New contributor




aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






aitee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2




    Why are you working so hard to undo what -x has added? Why not just remove the -x?
    – Jeff Schaller
    8 mins ago












  • 2




    Why are you working so hard to undo what -x has added? Why not just remove the -x?
    – Jeff Schaller
    8 mins ago







2




2




Why are you working so hard to undo what -x has added? Why not just remove the -x?
– Jeff Schaller
8 mins ago




Why are you working so hard to undo what -x has added? Why not just remove the -x?
– Jeff Schaller
8 mins ago










1 Answer
1






active

oldest

votes

















up vote
0
down vote













The main limitation you're running into is that + is an extended regular expression feature, so you'll need to enable extended regular expression functionality; with GNU sed, that's with the -r flag:



./test.sh 2>&1 | sed -r 's/^++ //'


I made two other changes:



  • added a trailing space, so that debugged commands show up left-aligned

  • removed the /g flag, since the regex is anchored, there can be only one match per line




share




















  • Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
    – Jeff Schaller
    46 secs ago










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: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






aitee is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477330%2fhow-can-i-use-sed-to-edit-bash-debug-output-bash-x%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













The main limitation you're running into is that + is an extended regular expression feature, so you'll need to enable extended regular expression functionality; with GNU sed, that's with the -r flag:



./test.sh 2>&1 | sed -r 's/^++ //'


I made two other changes:



  • added a trailing space, so that debugged commands show up left-aligned

  • removed the /g flag, since the regex is anchored, there can be only one match per line




share




















  • Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
    – Jeff Schaller
    46 secs ago














up vote
0
down vote













The main limitation you're running into is that + is an extended regular expression feature, so you'll need to enable extended regular expression functionality; with GNU sed, that's with the -r flag:



./test.sh 2>&1 | sed -r 's/^++ //'


I made two other changes:



  • added a trailing space, so that debugged commands show up left-aligned

  • removed the /g flag, since the regex is anchored, there can be only one match per line




share




















  • Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
    – Jeff Schaller
    46 secs ago












up vote
0
down vote










up vote
0
down vote









The main limitation you're running into is that + is an extended regular expression feature, so you'll need to enable extended regular expression functionality; with GNU sed, that's with the -r flag:



./test.sh 2>&1 | sed -r 's/^++ //'


I made two other changes:



  • added a trailing space, so that debugged commands show up left-aligned

  • removed the /g flag, since the regex is anchored, there can be only one match per line




share












The main limitation you're running into is that + is an extended regular expression feature, so you'll need to enable extended regular expression functionality; with GNU sed, that's with the -r flag:



./test.sh 2>&1 | sed -r 's/^++ //'


I made two other changes:



  • added a trailing space, so that debugged commands show up left-aligned

  • removed the /g flag, since the regex is anchored, there can be only one match per line





share











share


share










answered 1 min ago









Jeff Schaller

34.3k951114




34.3k951114











  • Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
    – Jeff Schaller
    46 secs ago
















  • Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
    – Jeff Schaller
    46 secs ago















Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
– Jeff Schaller
46 secs ago




Note that once you commingle stdout and stderr, any actual (stdout) output with leading plus signs will also be stripped.
– Jeff Schaller
46 secs ago










aitee is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















aitee is a new contributor. Be nice, and check out our Code of Conduct.












aitee is a new contributor. Be nice, and check out our Code of Conduct.











aitee is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f477330%2fhow-can-i-use-sed-to-edit-bash-debug-output-bash-x%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)