LinuxQuestions.org
Help answer threads with 0 replies.
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 12-07-2009, 12:50 AM   #1
xsyntax
LQ Newbie
 
Registered: Dec 2009
Posts: 7

Rep: Reputation: 0
Question Remove lines in text file that contain two '@' symbols


I am trying to write a script that will scan a list of e-mail addresses and remove any lines that contain more than one '@' symbol, and pipe the lines that don't match to STDOUT.

example:
email@domain.com
bob.smith@domain.comgeorge@domain.com <-- remove this line
john@newb.com

Any ideas would be greatly appreciated.

Thanks.
 
Old 12-07-2009, 01:05 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi, welcome to LQ!


sed -i '/@@/d' file
 
Old 12-07-2009, 01:58 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
To remove lines containing two (or more, consecutive and non-consecutive) @ characters, use '/@.*@/d'
Code:
c:~ echo 'email@@domain.com
bob.smith@domain.comgeorge@domain.come
john@newb.com' | sed '/@.*@/d'
john@newb.com
 
Old 12-07-2009, 02:18 AM   #4
xsyntax
LQ Newbie
 
Registered: Dec 2009
Posts: 7

Original Poster
Rep: Reputation: 0
hey guys, thanks for replying. tinkster, i tried your code but it didn't seam to work for me, however i tried to dig a few ideas with regex and was able to use this:

grep -v '.*\@.*\@'


catkin, haven't tried the code you just posted, but i may be able to use your code with a -i and make my life a little easier.

thanks for the help.
 
Old 12-07-2009, 01:17 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Ooops ... I must have been away in lala-land. I was
searching for two consecutive @ ... my apologies.
 
Old 12-07-2009, 05:58 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
shell
Code:
while read -r line
do
 case "$line" in
    *@*@* ) echo "invalid: $line";;
    * ) echo "ok: $line";;
 esac
done <"file"
output
Code:
$ ./shell.sh
ok: email@domain.com
invalid: bob.smith@domain.comgeorge@domain.com <-- remove this line
ok: john@newb.com
gawk:
Code:
$ awk '!/.*@.*@/' file
email@domain.com
john@newb.com

Last edited by ghostdog74; 12-07-2009 at 05:59 PM.
 
  


Reply

Tags
awk, sed



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
Remove lines in a text file based on another text file asiandude Programming 10 01-29-2009 10:59 AM
Adding lines of text to beginning of a text file BillKat Programming 2 01-19-2009 10:40 AM
Grab text lines in text file LULUSNATCH Programming 1 12-02-2005 10:55 AM
Remove odd lines from a text file Mr. Gone Programming 2 09-19-2005 11:16 AM
How to remove lines from a file doza Linux - General 2 04-27-2005 11:59 AM

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

All times are GMT -5. The time now is 07:29 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
Open Source Consulting | Domain Registration