LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 07: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, 03:09 AM   #2
toreric
Member
 
Registered: Dec 2005
Location: Tväråmark, Sweden
Distribution: Debian/Kubuntu
Posts: 105

Rep: Reputation: 27
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, 04:03 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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, 04:56 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

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


Reply



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 02:30 PM
SED, or GREP Command edwardcode Programming 24 04-18-2013 06:37 AM
[SOLVED] How do I list 'WORDS' containing a specific character? awk,sed,grep? rohit.dhaval1 Linux - Newbie 10 08-22-2012 09:08 AM
Remove first character with sed and grep r_jr Programming 11 02-04-2012 03:37 AM
[SOLVED] sed command to replace special character / Lokelo Linux - Newbie 11 11-23-2011 07:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:41 AM.

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
Open Source Consulting | Domain Registration