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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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
Posts: 8,578
|
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: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
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,697
|
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.
|
|
|
All times are GMT -5. The time now is 07:29 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
|
|