Grep -v filter not workingHow to feed the results of date command into grep to filter results of another...

Should I put my name first, or last in the team members list

Using Python in a Bash Script

Raindrops in Python

Why didn't Stark and Nebula use jump points with their ship to go back to Earth?

Correct word for a little toy that always stands up?

Creating a new Dataset column using a map from a second Dataset

Why would anyone ever invest in a cash-only etf?

Was Donald Trump at ground zero helping out on 9-11?

How to foreshadow to avoid a 'deus ex machina'-construction

How do you deal with characters with multiple races?

What Marvel character has this 'W' symbol?

What would the United Kingdom's "optimal" Brexit deal look like?

Why did some Apollo missions carry a grenade launcher?

PCB design using code instead of clicking a mouse?

Just how much information should you share with a former client?

How can I solve this sudoku?

How can flights operated by the same company have such different prices when marketed by another?

Are all French verb conjugation tenses and moods practical and efficient?

How does Asimov's second law deal with contradictory orders from different people?

Why does one get the wrong value when printing counters together?

Would people understand me speaking German all over Europe?

Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?

Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here

How to innovate in OR



Grep -v filter not working


How to feed the results of date command into grep to filter results of another commandWhy does grep not work with redirection?grep command giving errorwhy grep does not print the entire line?How do I filter stdout of a program through grep while still controlling the program?Why grep on remote system says file or directory not availableGrep not working on CSV using blacklistGrep file contents EXCEPT match case WITH contextWhy doesn't grep remove lines of terminal output from find command by default?Grep Ignoring Pipe?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I want to filter grep results by using grep -v option.
But the output does not differ when using a particular pattern.
contents of log.log:



ERROR
error
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


When I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -v 'error'


gives output:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


But if I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -vi '<STATUS>ERROR</STATUS>'


It still gives the output as:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


Whereas I am expecting:



ERROR
EXCEPTION
exception
<MessageType>ERROR</MessageType>


Why is this happening?










share|improve this question

















bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.












  • 3





    When I run the command it works. Please look for typos.

    – hellcode
    Oct 29 '15 at 10:30






  • 1





    Given that the command works for me, you should make a bug report against your implementation of "grep".

    – schily
    Oct 29 '15 at 10:42






  • 1





    What operating system are you on? Is your grep aliased to anything? What's the output of type grep?

    – terdon
    Oct 29 '15 at 12:55






  • 3





    Any chance you have got non-printable characters in your '<STATUS>ERROR</STATUS>' line?

    – Harald
    Oct 29 '15 at 22:02


















1















I want to filter grep results by using grep -v option.
But the output does not differ when using a particular pattern.
contents of log.log:



ERROR
error
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


When I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -v 'error'


gives output:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


But if I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -vi '<STATUS>ERROR</STATUS>'


It still gives the output as:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


Whereas I am expecting:



ERROR
EXCEPTION
exception
<MessageType>ERROR</MessageType>


Why is this happening?










share|improve this question

















bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.












  • 3





    When I run the command it works. Please look for typos.

    – hellcode
    Oct 29 '15 at 10:30






  • 1





    Given that the command works for me, you should make a bug report against your implementation of "grep".

    – schily
    Oct 29 '15 at 10:42






  • 1





    What operating system are you on? Is your grep aliased to anything? What's the output of type grep?

    – terdon
    Oct 29 '15 at 12:55






  • 3





    Any chance you have got non-printable characters in your '<STATUS>ERROR</STATUS>' line?

    – Harald
    Oct 29 '15 at 22:02














1












1








1


1






I want to filter grep results by using grep -v option.
But the output does not differ when using a particular pattern.
contents of log.log:



ERROR
error
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


When I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -v 'error'


gives output:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


But if I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -vi '<STATUS>ERROR</STATUS>'


It still gives the output as:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


Whereas I am expecting:



ERROR
EXCEPTION
exception
<MessageType>ERROR</MessageType>


Why is this happening?










share|improve this question
















I want to filter grep results by using grep -v option.
But the output does not differ when using a particular pattern.
contents of log.log:



ERROR
error
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


When I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -v 'error'


gives output:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


But if I run the command:



egrep -wi 'error|exception' /temp/log.log | grep -vi '<STATUS>ERROR</STATUS>'


It still gives the output as:



ERROR
EXCEPTION
exception
<STATUS>ERROR</STATUS>
<MessageType>ERROR</MessageType>


Whereas I am expecting:



ERROR
EXCEPTION
exception
<MessageType>ERROR</MessageType>


Why is this happening?







bash command-line grep pipe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 29 '15 at 10:37









hellcode

5021 gold badge5 silver badges14 bronze badges




5021 gold badge5 silver badges14 bronze badges










asked Oct 29 '15 at 10:07









AB DCAB DC

1063 bronze badges




1063 bronze badges






bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.









bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 1 hour ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 3





    When I run the command it works. Please look for typos.

    – hellcode
    Oct 29 '15 at 10:30






  • 1





    Given that the command works for me, you should make a bug report against your implementation of "grep".

    – schily
    Oct 29 '15 at 10:42






  • 1





    What operating system are you on? Is your grep aliased to anything? What's the output of type grep?

    – terdon
    Oct 29 '15 at 12:55






  • 3





    Any chance you have got non-printable characters in your '<STATUS>ERROR</STATUS>' line?

    – Harald
    Oct 29 '15 at 22:02














  • 3





    When I run the command it works. Please look for typos.

    – hellcode
    Oct 29 '15 at 10:30






  • 1





    Given that the command works for me, you should make a bug report against your implementation of "grep".

    – schily
    Oct 29 '15 at 10:42






  • 1





    What operating system are you on? Is your grep aliased to anything? What's the output of type grep?

    – terdon
    Oct 29 '15 at 12:55






  • 3





    Any chance you have got non-printable characters in your '<STATUS>ERROR</STATUS>' line?

    – Harald
    Oct 29 '15 at 22:02








3




3





When I run the command it works. Please look for typos.

– hellcode
Oct 29 '15 at 10:30





When I run the command it works. Please look for typos.

– hellcode
Oct 29 '15 at 10:30




1




1





Given that the command works for me, you should make a bug report against your implementation of "grep".

– schily
Oct 29 '15 at 10:42





Given that the command works for me, you should make a bug report against your implementation of "grep".

– schily
Oct 29 '15 at 10:42




1




1





What operating system are you on? Is your grep aliased to anything? What's the output of type grep?

– terdon
Oct 29 '15 at 12:55





What operating system are you on? Is your grep aliased to anything? What's the output of type grep?

– terdon
Oct 29 '15 at 12:55




3




3





Any chance you have got non-printable characters in your '<STATUS>ERROR</STATUS>' line?

– Harald
Oct 29 '15 at 22:02





Any chance you have got non-printable characters in your '<STATUS>ERROR</STATUS>' line?

– Harald
Oct 29 '15 at 22:02










1 Answer
1






active

oldest

votes


















0














The problem occurs due to the egrep -w 'error|exception'. This command adds special characters before and after the pattern (ie. error or exception) for highlighting these patterns in the grep result.



It is as Harald mentioned. The 'ERROR' pattern did not match grep output statement as the 'ERROR' between the STATUS tags in grep output had some special characters added to it by the -w flag.



Hence when the egrep's result was sent to grep -v command, it failed to match the pattern.






share|improve this answer





















  • 1





    No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

    – kos
    Oct 30 '15 at 5:22













  • oh I did not know that, but my std ouput is a terminal

    – AB DC
    Oct 30 '15 at 5:29






  • 1





    The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

    – kos
    Oct 30 '15 at 5:38
















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


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f239461%2fgrep-v-filter-not-working%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









0














The problem occurs due to the egrep -w 'error|exception'. This command adds special characters before and after the pattern (ie. error or exception) for highlighting these patterns in the grep result.



It is as Harald mentioned. The 'ERROR' pattern did not match grep output statement as the 'ERROR' between the STATUS tags in grep output had some special characters added to it by the -w flag.



Hence when the egrep's result was sent to grep -v command, it failed to match the pattern.






share|improve this answer





















  • 1





    No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

    – kos
    Oct 30 '15 at 5:22













  • oh I did not know that, but my std ouput is a terminal

    – AB DC
    Oct 30 '15 at 5:29






  • 1





    The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

    – kos
    Oct 30 '15 at 5:38


















0














The problem occurs due to the egrep -w 'error|exception'. This command adds special characters before and after the pattern (ie. error or exception) for highlighting these patterns in the grep result.



It is as Harald mentioned. The 'ERROR' pattern did not match grep output statement as the 'ERROR' between the STATUS tags in grep output had some special characters added to it by the -w flag.



Hence when the egrep's result was sent to grep -v command, it failed to match the pattern.






share|improve this answer





















  • 1





    No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

    – kos
    Oct 30 '15 at 5:22













  • oh I did not know that, but my std ouput is a terminal

    – AB DC
    Oct 30 '15 at 5:29






  • 1





    The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

    – kos
    Oct 30 '15 at 5:38
















0












0








0







The problem occurs due to the egrep -w 'error|exception'. This command adds special characters before and after the pattern (ie. error or exception) for highlighting these patterns in the grep result.



It is as Harald mentioned. The 'ERROR' pattern did not match grep output statement as the 'ERROR' between the STATUS tags in grep output had some special characters added to it by the -w flag.



Hence when the egrep's result was sent to grep -v command, it failed to match the pattern.






share|improve this answer













The problem occurs due to the egrep -w 'error|exception'. This command adds special characters before and after the pattern (ie. error or exception) for highlighting these patterns in the grep result.



It is as Harald mentioned. The 'ERROR' pattern did not match grep output statement as the 'ERROR' between the STATUS tags in grep output had some special characters added to it by the -w flag.



Hence when the egrep's result was sent to grep -v command, it failed to match the pattern.







share|improve this answer












share|improve this answer



share|improve this answer










answered Oct 30 '15 at 5:12









AB DCAB DC

1063 bronze badges




1063 bronze badges











  • 1





    No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

    – kos
    Oct 30 '15 at 5:22













  • oh I did not know that, but my std ouput is a terminal

    – AB DC
    Oct 30 '15 at 5:29






  • 1





    The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

    – kos
    Oct 30 '15 at 5:38
















  • 1





    No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

    – kos
    Oct 30 '15 at 5:22













  • oh I did not know that, but my std ouput is a terminal

    – AB DC
    Oct 30 '15 at 5:29






  • 1





    The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

    – kos
    Oct 30 '15 at 5:38










1




1





No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

– kos
Oct 30 '15 at 5:22







No, it doesn't add special characters to color the output if the output is not a terminal: egrep -wi 'error|exception' /temp/log.log | hexdump -c. You probably have a bugged version of grep (or, more likely, as Harald mentioned, strange characters in the <STATUS>ERROR</STATUS> line). Please add the output of hexdump -c /temp/log.log to your question

– kos
Oct 30 '15 at 5:22















oh I did not know that, but my std ouput is a terminal

– AB DC
Oct 30 '15 at 5:29





oh I did not know that, but my std ouput is a terminal

– AB DC
Oct 30 '15 at 5:29




1




1





The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

– kos
Oct 30 '15 at 5:38







The standard output is normally the terminal, but if you redirect the output to another command the standard output becomes the anonymous pipe generated by | to pass the output to the second command. Try egrep -wi 'error|exception' /temp/log.log | hexdump -c, hexdump -c will show the output as read by grep in the misbehaving command. There are no color escapes in the hexdump -c output. I suspect your file has some strange characters, so check the output of hexdump -c /temp/log.log (or maybe add it to the question). Otherwise, you found a bug in your grep version.

– kos
Oct 30 '15 at 5:38




















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f239461%2fgrep-v-filter-not-working%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

Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...