LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Avoiding junk character to using "grep and sed) command (https://www.linuxquestions.org/questions/linux-newbie-8/avoiding-junk-character-to-using-grep-and-sed-command-4175492733/)

san7752 01-27-2014 07:10 AM

Avoiding junk character to using "grep and sed) command
 
Hi All,

I need help regarding to use grep command. I am using following grep command:

grep 'notify@dtainc.us' virtual

I want to extract all the mail id which contain "notify" in virtual file.

right now if i am executing above command it's working fine
but its coming with junk '#' header .. I want to avoid this '#' character in my output. see the result:
==================================
$grep 'notify@dtainc.us' virtual

# abc.notify@abc.us
sddfd.notify@dtainc.us sdfdf@dtainc.us,dfd@dfd.com,Mende.Wi...@buyerzone.com
# tibersoft.notify@dtainc.us
============================

Please help me !
Thanks in advance.
Sanjeev

toreric 02-03-2014 03:09 AM

My example:

$ cat txtex
# txtex
asdsf.notify@lkfgj.wq
#
# abc.notify@abc.us
sddfd.notify@dtainc.us
sdfdf@dtainc.us
dfd@dfd.com
# tibersoft.notify@dtainc.us

Try this:

$ grep -v "^#" txtex | grep notify@
asdsf.notify@lkfgj.wq
sddfd.notify@dtainc.us

syg00 02-03-2014 04:03 AM

Don't use either grep or sed for logical AND situations - awk is much neater and only reads the input once.
Code:

awk '!/^#/ && /notify@/' infile

grail 02-03-2014 04:56 AM

Well you could use sed, just a little trickier:
Code:

sed -n '/notify@/{/^#/!p}' file


All times are GMT -5. The time now is 01:27 PM.