0

I am using grep to printout the matching lines from a very large file from which i got hundreds of matches, some of them are not interesting i want to exclude those matching which are not interesting

grep "WARNING" | grep -v "WARNING_HANDLING_THREAD" path # i tried this

When I grep the file for warning I get

0-00:00:33.392 (2127:127:250:02 = 21.278532 Fri Feb 1 10:17:22 2019) <3:0x000a>:[89]:[enter]: cest_handleFreeReq.c:116: [WARNING]: cest_handleFreeReq: sent from DECA ->UCS

0-00:00:38.263 (2189:022:166:06 = 21.891510 Fri Feb 1 10:17:28 2019) <3:0x000a>:[89]:[enter]: cest_handleConfigReq.c:176: [WARNING]: cest_handleConfigReq.c: GroupConfig NOT present.

0-00:00:38.263 (2189:022:167:03 = 21.891510 Fri Feb 1 10:17:28 2019) <3:0x000a>:[89]:[enter]: cest_handleConfigReq.c:194: [WARNING]: cest_handleConfigReq: physicalConfig NOT present.

60 0x6d77 0 0x504ea | 2 18 | 0 0 | 4 12 | 647 | 14685 0 0.0 0 500 500 | 0 | 0 | 38 | ETH_DRV_WARNING_HANDLING_thread 60 0 | 0 0 | 0 0 0 | 0 0 0 0 0 0 ! N/A N/A N/A N/A N/A N/A |ETH_DRV_WARNING_HANDLING_thread

WARNING: List of threads violating the heap & stack limit

I want to exclude the last lines which are not interesting

0-00:00:33.392 (2127:127:250:02 = 21.278532 Fri Feb 1 10:17:22 2019) <3:0x000a>:[89]:[enter]: cest_handleFreeReq.c:116: [WARNING]: cest_handleFreeReq: sent from DECA ->UCS

0-00:00:38.263 (2189:022:166:06 = 21.891510 Fri Feb 1 10:17:28 2019) <3:0x000a>:[89]:[enter]: cest_handleConfigReq.c:176: [WARNING]: cest_handleConfigReq.c: GroupConfig NOT present.

0-00:00:38.263 (2189:022:167:03 = 21.891510 Fri Feb 1 10:17:28 2019) <3:0x000a>:[89]:[enter]: cest_handleConfigReq.c:194: [WARNING]: cest_handleConfigReq: physicalConfig NOT present.

Is there a way to do this using grep find or any other tool?

Thank you

kuchu
  • 23
  • 4
  • 1
    Please add sample input and your desired output for that sample input to your question. – Cyrus Feb 01 '19 at 09:58
  • @Cyrus i didn't get what you are asking, the blocks in the question above is the sample output when did grep and immediate block is the output how i what the results to look like. have a log file from which i am grepping the word warning but i want to exclude some warnings like violating stack and heap limit lines i want to know how to do that to exclude some of the lines which are not interesting from grep. – kuchu Feb 01 '19 at 11:08

1 Answers1

0

Note that the substring thread is in lower case in the data, but in upper case in your expression.

Instead, use

grep -F 'WARNING' logfile | grep -F -v 'WARNING_HANDLING_thread'

The -F make grep use string comparisons rather than regular expression matching (this is not really related to your current issue, but just a way of showing that we know what type of pattern we're matching with).

Another option would be to make the second grep do case insensitive matching with -i:

grep -F 'WARNING' logfile | grep -Fi -v 'WARNING_HANDLING_THREAD'

In this case though, I would probably match the [WARNING] tag instead:

grep -F '[WARNING]:' logfile

Note that here we need the -F so that grep interprets the pattern as a string and not as a regular expression matching any single character out of the W, A, R, N, I, G set, followed by a :.

Kusalananda
  • 14,885
  • 3
  • 41
  • 52
  • this is just an sample trace log, i also have some uninterested things with '[WARNING]:' my bad i haven't made that thing clear in my question. but if i use **grep -F 'WARNING' | grep -F -v 'WARNING_HANDLING_thread'** it is printing the whole log not only the lines which has WARNING excluding the second grep content – kuchu Feb 01 '19 at 13:22
  • @kuchu Huh? How can you get the _whole_ log? I'm assuming that you either pipe the log to the first `grep` or that you use `grep -F 'WARNING' logfile | grep -F -v '...other string ...'`, right? – Kusalananda Feb 01 '19 at 13:40
  • **grep -F 'ERROR' | grep -F -v 'WARNING_HANDLING_thread' logfile** this is what i am using @kusalananda – kuchu Feb 01 '19 at 14:13
  • @kuchu The first `grep` would do _nothing_ there. Give the logfile to the first `grep`. The second `grep` should read the output of the first `grep`, not the logfile. I have updated the answer to reflect this. – Kusalananda Feb 01 '19 at 14:19