"Problem description"
Extract the contact email address from the following file as follows:
<[email protected]>, Li Junqing <[email protected]>, Shaos <[email protected]>, Li Willow <[email protected]>, Mengjin <[email protected]>, Wang Liguang <[email protected]>
"Solution"
1.awk
$awk ' {for (i=1;i<=nf;i++) if ($i ~ <) {print gensub (/< (. +) >.*/, "\\1", "G", $i)} ' a.txt [email protected][em Ail protected][email protected][email protected][email protected][email protected] $awk ' {for (i=1;i<=nf;i++) if ($i ~ "<") {print $i}} ' a.txt |awk-f ' <|> ' {print $} ' [email protected][email protected][email Protected][email Pro Tected][email Protected][email protected]
2.sed combined with awk
$sed-R ' s#,# #g ' a.txt |tr ' > ' \ n ' |awk-f ' < ' {print $NF} ' |sed '/^\s*$/d ' [email protected][email protected][emai L Protected][email protected][email Protected][email protected]
Sed '/^\s*$/d ' to delete empty lines
3.grep
$grep-op ' (?<=<) (. *?) (?=>) ' a.txt [email protected][email protected][email protected][email protected][email protected][email protected]
awk extract Contact mailbox (for loop, gensub, etc.)