|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Selective grep
I have to grep out only email address from a column. It has characters appended and prepended Code:
F=<sss1@domain.com> <sss2@domain.com> (sss3@domain.com) <sss4@domain.com> Whatever added before and after email, I should be able to grep out only emails. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Hi Code:
$ grep -o '[[:alnum:]]*@[[:alpha:]]*\.com' file sss1@domain.com sss2@domain.com sss3@domain.com sss4@domain.com Guru. |
| The Following User Says Thank You to guruprasadpr For This Useful Post: | ||
anil510 (05-18-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thank you guruprasadpr,
If there are mixed tlds, like .com, .net, .co.in, .in etc.. |
|
#4
|
||||
|
||||
|
A slight extension to guruprasadpr's solution: Code:
grep -Eo '[[:alnum:]]*@[[:alpha:]]*(\.[a-z]{2,4})+' file |
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Code:
$ nawk -F"[<>()]" '{print $2}' test.txt
sss1@domain.com
sss2@domain.com
sss3@domain.com
sss4@domain.com |
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
Code:
sed 's/.*[<(]\([^>)]*\)[>)]/\1/g' infile |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
Quote:
Code:
# cat /root/gmail.txt now_u.k12@gmail.com c.gg@gmail.com s_klk@gmail.com When _ or . character is in email, it gives wrong result. Code:
# cat /root/gmail.txt | grep -o '[[:alnum:]]*@gmail.com' |sort|uniq -c|sort -nk 1
1 gg@gmail.com
1 k12@gmail.com
1 klk@gmail.comHow to solve this? |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with selective ls | newbie_01 | UNIX for Dummies Questions & Answers | 7 | 04-03-2012 07:58 AM |
| selective grep | verse123 | UNIX for Dummies Questions & Answers | 6 | 01-24-2012 10:19 AM |
| selective printing | JoeColeEPL9 | Shell Programming and Scripting | 4 | 09-22-2011 08:02 AM |
| Selective Umask | baanprog | UNIX for Advanced & Expert Users | 3 | 08-03-2006 09:48 AM |
| Using `tar` for a selective backup. | Cameron | Filesystems, Disks and Memory | 2 | 07-16-2002 09:10 AM |
|
|