-   Linux - Newbie (
-   -   Remove lines in text file that contain two '@' symbols (

xsyntax 12-07-2009 12: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: <-- remove this line

Any ideas would be greatly appreciated.


Tinkster 12-07-2009 01:05 AM

Hi, welcome to LQ!

sed -i '/@@/d' file

catkin 12-07-2009 01:58 AM

To remove lines containing two (or more, consecutive and non-consecutive) @ characters, use '/@.*@/d'

c:~ echo '
bob.smith@domain.comgeorge@domain.come' | sed '/@.*@/d'

xsyntax 12-07-2009 02: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 01:17 PM

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

ghostdog74 12-07-2009 05:58 PM


while read -r line
 case "$line" in
    *@*@* ) echo "invalid: $line";;
    * ) echo "ok: $line";;
done <"file"


$ ./
invalid: <-- remove this line


$ awk '!/.*@.*@/' file

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