Logging only a specific part of stderr?
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example
Running tar -xzf file 2>> log.txt
, and getting an error
tar: Child returned status 1
I only want to log the Child returned status 1 part, and not include the command name.
stderr
add a comment |Â
up vote
1
down vote
favorite
Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example
Running tar -xzf file 2>> log.txt
, and getting an error
tar: Child returned status 1
I only want to log the Child returned status 1 part, and not include the command name.
stderr
1
You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
â thrig
Oct 2 '17 at 14:15
Do you want to remove thetar:
prefix off every error message bytar
, or just that one and discard every other error message by bothtar
andgzip
?
â Stéphane Chazelas
Oct 2 '17 at 22:10
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example
Running tar -xzf file 2>> log.txt
, and getting an error
tar: Child returned status 1
I only want to log the Child returned status 1 part, and not include the command name.
stderr
Couldn't find anything on this, but I'm trying to only log a specific part of stderr to a file. So for example
Running tar -xzf file 2>> log.txt
, and getting an error
tar: Child returned status 1
I only want to log the Child returned status 1 part, and not include the command name.
stderr
stderr
edited Oct 2 '17 at 20:39
Hauke Laging
53.7k1282130
53.7k1282130
asked Oct 2 '17 at 4:57
Hanson Duan
61
61
1
You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
â thrig
Oct 2 '17 at 14:15
Do you want to remove thetar:
prefix off every error message bytar
, or just that one and discard every other error message by bothtar
andgzip
?
â Stéphane Chazelas
Oct 2 '17 at 22:10
add a comment |Â
1
You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
â thrig
Oct 2 '17 at 14:15
Do you want to remove thetar:
prefix off every error message bytar
, or just that one and discard every other error message by bothtar
andgzip
?
â Stéphane Chazelas
Oct 2 '17 at 22:10
1
1
You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
â thrig
Oct 2 '17 at 14:15
You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
â thrig
Oct 2 '17 at 14:15
Do you want to remove the
tar:
prefix off every error message by tar
, or just that one and discard every other error message by both tar
and gzip
?â Stéphane Chazelas
Oct 2 '17 at 22:10
Do you want to remove the
tar:
prefix off every error message by tar
, or just that one and discard every other error message by both tar
and gzip
?â Stéphane Chazelas
Oct 2 '17 at 22:10
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
0
down vote
tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile
add a comment |Â
up vote
0
down vote
With zsh
, you can do:
tar -xzf file 2> >(sed 's/^tar: //' >> file.log)
Which allows to retain tar
's exit status.
You can do something similar with ksh
, bash
or yash
though you'd have to use work arounds there to make sure sed
has finished by the time you run the next command if that command makes use of the file.log
.
Other option with bash
is to use:
sed 's/^tar: //' >> file.log 3>&-; 3>&1
tar_exit_status=$PIPESTATUS[0]
Note that with several shells, you can also call tar
with an empty argv[0] with:
(exec -a '' tar -xzf file)
In which case the error messages will look like:
: Child returned status 1
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile
add a comment |Â
up vote
0
down vote
tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile
add a comment |Â
up vote
0
down vote
up vote
0
down vote
tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile
tar -xzf file 3>&1 1>&2 2>&3 | grep -oP '^app: K.*$' | tee logfile
answered Oct 2 '17 at 20:38
Hauke Laging
53.7k1282130
53.7k1282130
add a comment |Â
add a comment |Â
up vote
0
down vote
With zsh
, you can do:
tar -xzf file 2> >(sed 's/^tar: //' >> file.log)
Which allows to retain tar
's exit status.
You can do something similar with ksh
, bash
or yash
though you'd have to use work arounds there to make sure sed
has finished by the time you run the next command if that command makes use of the file.log
.
Other option with bash
is to use:
sed 's/^tar: //' >> file.log 3>&-; 3>&1
tar_exit_status=$PIPESTATUS[0]
Note that with several shells, you can also call tar
with an empty argv[0] with:
(exec -a '' tar -xzf file)
In which case the error messages will look like:
: Child returned status 1
add a comment |Â
up vote
0
down vote
With zsh
, you can do:
tar -xzf file 2> >(sed 's/^tar: //' >> file.log)
Which allows to retain tar
's exit status.
You can do something similar with ksh
, bash
or yash
though you'd have to use work arounds there to make sure sed
has finished by the time you run the next command if that command makes use of the file.log
.
Other option with bash
is to use:
sed 's/^tar: //' >> file.log 3>&-; 3>&1
tar_exit_status=$PIPESTATUS[0]
Note that with several shells, you can also call tar
with an empty argv[0] with:
(exec -a '' tar -xzf file)
In which case the error messages will look like:
: Child returned status 1
add a comment |Â
up vote
0
down vote
up vote
0
down vote
With zsh
, you can do:
tar -xzf file 2> >(sed 's/^tar: //' >> file.log)
Which allows to retain tar
's exit status.
You can do something similar with ksh
, bash
or yash
though you'd have to use work arounds there to make sure sed
has finished by the time you run the next command if that command makes use of the file.log
.
Other option with bash
is to use:
sed 's/^tar: //' >> file.log 3>&-; 3>&1
tar_exit_status=$PIPESTATUS[0]
Note that with several shells, you can also call tar
with an empty argv[0] with:
(exec -a '' tar -xzf file)
In which case the error messages will look like:
: Child returned status 1
With zsh
, you can do:
tar -xzf file 2> >(sed 's/^tar: //' >> file.log)
Which allows to retain tar
's exit status.
You can do something similar with ksh
, bash
or yash
though you'd have to use work arounds there to make sure sed
has finished by the time you run the next command if that command makes use of the file.log
.
Other option with bash
is to use:
sed 's/^tar: //' >> file.log 3>&-; 3>&1
tar_exit_status=$PIPESTATUS[0]
Note that with several shells, you can also call tar
with an empty argv[0] with:
(exec -a '' tar -xzf file)
In which case the error messages will look like:
: Child returned status 1
answered Oct 2 '17 at 22:22
Stéphane Chazelas
283k53522859
283k53522859
add a comment |Â
add a comment |Â
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%2f395562%2flogging-only-a-specific-part-of-stderr%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
1
You would have to filter stderr through some process. However, removing the process name removes vital debugging info, so I would not do that.
â thrig
Oct 2 '17 at 14:15
Do you want to remove the
tar:
prefix off every error message bytar
, or just that one and discard every other error message by bothtar
andgzip
?â Stéphane Chazelas
Oct 2 '17 at 22:10