Grep ignoring help

When using grep I would like to ignore DEBUG=, but not ignore DEBUG=-g, DEBUG=-g -misalign. I only care about DEBUG= if there is something after the equal sign =. Things I wanna see.

DEBUG=-g
DEBUG=-g -misalign
DEBUG=-misalign
DEBUG=-xmemalign=1i

I am using sunos.

This is what I tried and thought would work. Thought with quotes and the -w option it would only match "DEBUG=".

grep -i debug | grep -vw "DEBUG="

Doesn't grep -i 'debug=.' guarantee, that after = there will be at least one more character?

$ cat -vet coke.txt
DEBUG=-g$
DEBUG=$
DEBUG=-g -misalign$
DEBUG=-misalign$
DEBUG= $
DEBUG=-xmemalign=1i$
$ grep -i 'DEBUG=[^ ]' coke.txt | cat -vet
DEBUG=-g$
DEBUG=-g -misalign$
DEBUG=-misalign$
DEBUG=-xmemalign=1i$

Obviously a space ( ) could be a tab - I'll let you enhance the regex.

Yes. I need to get better at regex :). I am doing a double grep because I still want to pick up things like $(DEBUG), #With debug, DEBUG+=-g, #Without debug, #With debug, etc.

then you/we need a better (more representative) input sample AND the desired output based on the input sample.

My data.

DEBUG=-g
Random stuff
DEBUG=
hi
DEBUG=-g -misalign
hi
echos
DEBUG=
boo
DEBUG=-misalign
stuff
DEBUG=-xmemalign=1i
tricky
DEBUG=
work
$(DEBUG)
#With debug
um
DEBUG=
running
DEBUG+=-g
out
#Without debug
of
DEBUG=
things
#With debug
to
DEBUG=
say
: cat -vetn junk2
     1  DEBUG=-g$
     2  Random stuff$
     3  DEBUG=$
     4  hi$
     5  DEBUG=-g -misalign$
     6  hi$
     7  echos$
     8  DEBUG=$
     9  boo$
    10  DEBUG=-misalign$
    11  stuff$
    12  DEBUG=-xmemalign=1i$
    13  tricky$
    14  DEBUG=$
    15  work$
    16  $(DEBUG) $
    17  #With debug $
    18  um$
    19  DEBUG=$
    20  running$
    21  DEBUG+=-g $
    22  out$
    23  #Without debug $
    24  of$
    25  DEBUG=$
    26  things$
    27  #With debug$
    28  to$
    29  DEBUG=$
    30  say$

How is this working? Some weird sunos behavior?

: cat -vetn junk2 | grep -i debug | grep -vw "DEBUG=."
     1  DEBUG=-g$
     5  DEBUG=-g -misalign$
    10  DEBUG=-misalign$
    12  DEBUG=-xmemalign=1i$
    16  $(DEBUG) $
    17  #With debug $
    21  DEBUG+=-g $
    23  #Without debug $
    27  #With debug$

: cat -vetn junk2 | grep -i debug | grep -vw 'DEBUG=[^ ]'
     1  DEBUG=-g$
     5  DEBUG=-g -misalign$
    10  DEBUG=-misalign$
    12  DEBUG=-xmemalign=1i$
    16  $(DEBUG) $
    17  #With debug $
    21  DEBUG+=-g $
    23  #Without debug $
    27  #With debug$

My man pages say:

       -v    Prints all lines except those that contain the pattern.

       -w    Searches  for the expression as a word as if surrounded by \< and
             \>.

So shouldn't it ignore all of this with grep -vw 'DEBUG=[^ ]' and grep -vw "DEBUG=."?

 1  DEBUG=-g$
 5  DEBUG=-g -misalign$
10  DEBUG=-misalign$
12  DEBUG=-xmemalign=1i$

Based on your "original", 30-line long input file, and your initial description of desired output, I get:

ubuntu-mate@ubuntu-mate:~$ grep -i 'debug' input.txt | grep -v 'DEBUG=$'
DEBUG=-g
DEBUG=-g -misalign
DEBUG=-misalign
DEBUG=-xmemalign=1i
$(DEBUG)
#With debug
DEBUG+=-g
#Without debug
#With debug

as it discards all the lines with immediate newline character after the equal sign (given that there is an equal sign in the line of text, and that it immediately follows the 'DEBUG')

So, given the above sample input, what would be the desired output?
I get:

$ grep -i 'DEBUG=[^ ]' coke.txt
DEBUG=-misalign
DEBUG=-xmemalign=1i

What is it that you're after?

Brain not thinking. The cat -vet is adding the newline $ character. Was just trying to add line numbers to make it more readable. Sorry about that.

This is what the data is supposed to be.

DEBUG=-g
Random stuff
DEBUG=
hi
DEBUG=-g -misalign
hi
echos
DEBUG=
boo
DEBUG=-misalign
stuff
DEBUG=-xmemalign=1i
tricky
DEBUG=
work
$(DEBUG)
#With debug
um
DEBUG=
running
DEBUG+=-g
out
#Without debug
of
DEBUG=
things
#With debug
to
DEBUG=
say

Yes, I think I got previously, what the input data is supposed to be :wink:
Now I'm trying to understand, what the desired output is supposed to be, after you filter input through double grep pipeline. See my previous reply.

Wanna chop out lines containing this DEBUG=.

This is my desired output.

DEBUG=-g
DEBUG=-g -misalign
DEBUG=-misalign
DEBUG=-xmemalign=1i
$(DEBUG)
#With debug
DEBUG+=-g
#Without debug
#With debug

Also wanna keep these $(DEBUG), #With debug, DEBUG+=-g, #Without debug, #With debug,. That is why I am trying to do it in two stages. First pick up all the debug. Then chop out DEBUG=.

So, I think this is exactly what I got in my reply few minutes earlier :slight_smile:
Is this: grep -i 'debug' input.txt | grep -v 'DEBUG=$' the command line you're looking for? (when your file is named input.txt)

Sorry about that. Thought the dollar sign's $ were coming from cat -vet. Your right :). That works :). Thank you :).