我是AWK的新手,我在AWK有一些基本的想法。我想在一个文件中删除重复项, 例如:使用AWK如何去除这些类型的重复?
0008.ASIA. NS AS2.DNS.ASIA.CN.
0008.ASIA. NS AS2.DNS.ASIA.CN.
ns1.0008.asia. NS AS2.DNS.ASIA.CN.
www.0008.asia. NS AS2.DNS.ASIA.CN.
anish.asia NS AS2.DNS.ASIA.CN.
ns2.anish.asia NS AS2.DNS.ASIA.CN
ANISH.asia. NS AS2.DNS.ASIA.CN.
这是一个示例文件,从使用此命令我得到这样的输出:
awk 'BEGIN{IGNORECASE=1}/^[^ ]+asia/ { gsub(/\.$/,"",$1);split($1,a,".")} length(a)==2{b[$1]++;}END{for (x in b)print x}'
0008.ASIA 。
anish.asia。
ANISH.asia
但是我要像这样输出
008.ASIA
anish.asia
或
008.ASIA
ANISH.asia
如何删除这些重复样的?
由于提前 阿尼什kumar.V
感谢您的即时效应初探,其实我在bash写了一个完整的脚本,现在我在最后阶段。如何在这部分调用蟒蛇在:-(
#!/bin/bash
current_date=`date +%d-%m-%Y_%H.%M.%S`
today=`date +%d%m%Y`
yesterday=`date -d 'yesterday' '+%d%m%Y'`
RootPath=/var/domaincount/asia/
MainPath=$RootPath${today}asia
LOG=/var/tmp/log/asia/asiacount$current_date.log
mkdir -p $MainPath
echo Intelliscan Process started for Asia TLD $current_date
exec 6>&1 >> $LOG
#################################################################################################
## Using Wget Downloading the Zone files it will try only one time
if ! wget --tries=1 --ftp-user=USERNAME --ftp-password=PASSWORD ftp://ftp.anish.com:21/zonefile/anish.zone.gz
then
echo Download Not Success Domain count Failed With Error
exit 1
fi
###The downloaded file in Gunzip format from that we need to unzip and start the domain count process####
gunzip asia.zone.gz > $MainPath/$today.asia
###### It will start the Count #####
awk '/^[^ ]+ASIA/ && !_[$1]++{print $1; tot++}END{print "Total",tot,"Domains"}' $MainPath/$today.asia > $RootPath/zonefile/$today.asia
awk '/Total/ {print $2}' $RootPath/zonefile/$today.asia > $RootPath/$today.count
a=$(< $RootPath/$today.count)
b=$(< $RootPath/$yesterday.count)
c=$(awk 'NR==FNR{a[$0];next} $0 in a{tot++}END{print tot}' $RootPath/zonefile/$today.asia $RootPath/zonefile/$yesterday.asia)
echo "$current_date Count For Asia TlD $a"
echo "$current_date Overall Count For Asia TlD $c"
echo "$current_date New Registration Domain Counts $((c - a))"
echo "$current_date Deleted Domain Counts $((c - b))"
exec >&6 6>&-
cat $LOG | mail -s "Asia Tld Count log" [email protected]
在这种
awk '/^[^ ]+ASIA/ && !_[$1]++{print $1; tot++}END{print "Total",tot,"Domains"}' $MainPath/$today.asia > $RootPath/zonefile/$today.asia
只是现在我正在寻找如何使用AWK对我更好地得到不同值,因此任何建议。谢谢再次感谢您立即作出反应。
对不起,但添加你在这里发布的整个Bash脚本并没有让事情变得更加清晰。您能否将您的问题简化为一个小例子以及您目前面临的问题的陈述? –
嗨现在问题是我的冷杉单独发布,我刚刚在这里显示我写了一个脚本...有没有可能使用AWK本身,我没有太多的想法在蟒蛇.. –
你能清理你的问题?这真的会有很大的帮助。 –