Register
It is currently Sat Jul 26, 2014 3:07 am

Chek file.txt with email inside


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Dec 13, 2013 7:37 am   

Joined: Mon Nov 25, 2013 10:04 am
Posts: 9
0 down vote favorite


I have a lot of txt files contain emails separated by space and I would like to check whether there is an invalid email inside it.

With this I check whether file.txt is empty or not:

Code:
for file in *.txt; do
    email=(grep $file)
    if [ -s "$file" ]; then
        echo "OK $file"
     else   
        echo "-- EMPTY $file"


My question is do I need to use grep for checking the validity of emails inside the file?

Code:
elif
        if [[ grep $file =~ "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" ]]
    then
        echo "Email address inside $file is valid."
    else
        echo "Email address inside $file contain $email is invalid."
    fi
done


Top
 Profile  
 PostPosted: Fri Dec 13, 2013 10:37 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
hi,

what do you think you're greping here ?
instead:
Code:
if grep -q "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" "$file"
then
:...
fi


Top
 Profile  
 PostPosted: Thu Dec 26, 2013 4:14 am   

Joined: Mon Nov 25, 2013 10:04 am
Posts: 9
there is a problem with LR LFRT end line unix dos


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP