[Hour] [Data] [IP] [ASN] [Country] [Domain ASN Responsable]
11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
11:37 12/12/2003 10.10.10.1 FATHER.COM 5 country Responsable of ASN
11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN
12:50 18/12/2003 100.100.10.1 son.com 8 country Responsable of ASN
12:55 18/12/2003 100.100.10.1 Cousin Corporation of America 8 country Responsable of ASN
I want to print just ASN that are about my responsibility, this example only that with ASN , 5 and 6.
Example: I am using this command
egrep '5|6' example
This is a output of my command.
11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
11:37 12/12/2003 10.10.10.1 FATHER.COM 5 country Responsable of ASN
11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN
But I wanted that my output wil be this:
ASN5=11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
11:37 12/12/2003 10.10.10.1 FATHER.COM 5 country Responsable of ASN
ASN6=11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN
Because after i wil need to send e-mail to ASN5 and ASN6 separated.
Using grep as you do will not work as it will capture 5 and 6 anywhere in the line. If you have a date or time that has a 5 or 6 in it, grep will return the line.
Have a go with this awk snippet:
awk '$5==5||$5==6{a[$5]=a[$5] (a[$5]?"\n":"") $0}END{for(i in a) print "ASN"i"=",a"\n"}' input.file
Because I will need other data in ASNS.
I want to do "Whois" in the field IP inside the ASNS variable
I wanted that for each line of my variable ASNS . The variable IP catch the value of field IP that is inside the $ASNS and to execute command whois, after this his send e-mail to me and starting again with second data of variable ASNS.And finally replacing field <IP> and field <data> set in my template.
I tried so , but isn't work. My for is wrong.
for I in `echo $ASNS`; do
IP= $ASNS | awk ' { print $3 } ' "is it field of my ip in my input.file"
for j in `echo $IP`; do
# Information of WHOIS
echo " **** WHOIS **** " > $EMAIL
$WHOIS $I >> $EMAIL
echo " *************** " >> $EMAIL
echo " " >> $EMAIL
# Conteudo do email
cat $TEMPLATE >> $EMAIL
sed -i s/"<IP>"/$I/ $EMAIL
DATA=`echo $ASNS | sed 's/ / /g'`
sed -i s#"<data>"#"$DATA"# $EMAIL
done
done
tags when you post data or code sample.
[*]Please remove useless UUOC
[*]State your environment/shell
Base on your second post you need something like:
# eval "$(awk '$5==5||$5==6{a[$5]=((a[$5])?a[$5]"\n":"ASN"$5"=\"")$0}END{for(i in a)print a"\""}' file)"
# echo "$ASN6"
11:40 14/12/2003 10.10.10.3 www.mother 6 country Responsable of ASN
11:45 14/12/2003 10.10.10.3 www.daugher 6 country Responsable of ASN
# echo "$ASN5"
11:35 10/12/2003 10.10.10.1 God.com 5 country Responsable of ASN
11:37 12/12/2003 10.10.10.1 www.father.com 5 country Responsable of ASN