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

Clash 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
bash sed scripting stderr
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.
add a comment |Â
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
bash sed scripting stderr
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-xhas added? Why not just remove the-x?
â Jeff Schaller
8 mins ago
add a comment |Â
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
bash sed scripting stderr
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
bash sed scripting stderr
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.
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-xhas added? Why not just remove the-x?
â Jeff Schaller
8 mins ago
add a comment |Â
2
Why are you working so hard to undo what-xhas 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
add a comment |Â
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
/gflag, since the regex is anchored, there can be only one match per line
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
add a comment |Â
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
/gflag, since the regex is anchored, there can be only one match per line
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
add a comment |Â
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
/gflag, since the regex is anchored, there can be only one match per line
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
add a comment |Â
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
/gflag, since the regex is anchored, there can be only one match per line
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
/gflag, since the regex is anchored, there can be only one match per line
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
add a comment |Â
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
add a comment |Â
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.
aitee is a new contributor. Be nice, and check out our Code of Conduct.
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
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
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
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
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
2
Why are you working so hard to undo what
-xhas added? Why not just remove the-x?â Jeff Schaller
8 mins ago