How can I use Awk inside a Perl script?
Posted
by papoyan
on Stack Overflow
See other posts from Stack Overflow
or by papoyan
Published on 2010-04-19T03:43:26Z
Indexed on
2010/04/19
23:53 UTC
Read the original article
Hit count: 172
I'm having trouble using the following code inside my Perl script, any advise is really appreciated, how to correct the syntax?
# If I execute in bash, it's working just fine
bash$ whois google.com | egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" |awk ' {for (i=1;i<=NF;i++) {if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ ) { print $i}}}'|head -n1
[email protected]
#-----------------------------------
#but this doesn't work
bash$ ./email.pl google.com
awk: {for (i=1;i<=NF;i++) {if ( ~ /[[:alpha:]]@[[:alpha:]]/ ) { print }}}
awk: ^ syntax error
# Here is my script
bash$ cat email.pl
####\#!/usr/bin/perl
$input = lc shift @ARGV;
$host = $input;
my $email = `whois $host | egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" |awk ' {for (i=1;i<=NF;i++) {if ( $i ~ /[[:alpha:]]@[[:alpha:]]/ ) { print $i}}}'|head -1`;
print my $email;
bash$
© Stack Overflow or respective owner