LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-27-2014, 08:10 AM   #1
san7752
LQ Newbie
 
Registered: Jan 2014
Posts: 1

Rep: Reputation: Disabled
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
 
Old 02-03-2014, 04:09 AM   #2
toreric
Member
 
Registered: Dec 2005
Location: Tväråmark, Sweden
Distribution: Debian/Kubuntu
Posts: 100

Rep: Reputation: 16
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
 
Old 02-03-2014, 05:03 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,833

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
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
 
Old 02-03-2014, 05:56 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Well you could use sed, just a little trickier:
Code:
sed -n '/notify@/{/^#/!p}' file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Use grep to grab a value in between character with a single command :/ Drigo Linux - Newbie 3 11-14-2013 03:30 PM
SED, or GREP Command edwardcode Programming 24 04-18-2013 07:37 AM
[SOLVED] How do I list 'WORDS' containing a specific character? awk,sed,grep? rohit.dhaval1 Linux - Newbie 10 08-22-2012 10:08 AM
Remove first character with sed and grep r_jr Programming 11 02-04-2012 04:37 AM
[SOLVED] sed command to replace special character / Lokelo Linux - Newbie 11 11-23-2011 08:59 AM


All times are GMT -5. The time now is 08:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration