LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Remove lines in text file that contain two '@' symbols (http://www.linuxquestions.org/questions/linux-newbie-8/remove-lines-in-text-file-that-contain-two-%40-symbols-773904/)

xsyntax 12-07-2009 01:50 AM

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.

Tinkster 12-07-2009 02:05 AM

Hi, welcome to LQ!


sed -i '/@@/d' file

catkin 12-07-2009 02:58 AM

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


xsyntax 12-07-2009 03:18 AM

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.

Tinkster 12-07-2009 02:17 PM

Ooops ... I must have been away in lala-land. I was
searching for two consecutive @ ... my apologies.

ghostdog74 12-07-2009 06:58 PM

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



All times are GMT -5. The time now is 11:45 PM.