awk problem

Randal L. Schwartz merlyn at stonehenge.com
Fri Aug 13 16:28:12 UTC 2010


>>>>> "Len" == Len Conrad <lconrad at Go2France.com> writes:

Len> I readfile or pipe this text, in any line order:
Len> rm90.steampick.info
Len> fgce172.lanejive.info
Len> smailer1.service.govdelivery.com
Len> fl49.orangetalon.info
Len> pollux.carespecial.info

Len> into a program to remove subdomains down to domain.tld :

Len> awk 'FS="." { print $(NF-1)"."$NF }'

Len> and get the first line doubled rather than processed like the other lines:

Len> rm90.steampick.info.rm90.steampick.info
Len> lanejive.info
Len> govdelivery.com
Len> orangetalon.info
Len> carespecial.info

Yes, that would be the expected behavior.

You need to set the FS *before* processing the first line.

Either use -F ., or a BEGIN block.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion


More information about the freebsd-questions mailing list