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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-07-2009, 12:50 AM
|
#1
|
|
LQ Newbie
Registered: Dec 2009
Posts: 7
Rep:
|
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.
|
|
|
|
12-07-2009, 01:05 AM
|
#2
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Hi, welcome to LQ!
sed -i '/@@/d' file
|
|
|
|
12-07-2009, 01:58 AM
|
#3
|
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian Squeeze (server), Slackware 13.37 (netbook), Slackware64 14.0 (desktop),
Posts: 8,357
|
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
|
|
|
|
12-07-2009, 02:18 AM
|
#4
|
|
LQ Newbie
Registered: Dec 2009
Posts: 7
Original Poster
Rep:
|
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.
|
|
|
|
12-07-2009, 01:17 PM
|
#5
|
|
Moderator
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,903
|
Ooops ... I must have been away in lala-land. I was
searching for two consecutive @ ... my apologies.
|
|
|
|
12-07-2009, 05:58 PM
|
#6
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:50 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|