From owner-freebsd-questions@freebsd.org Tue Apr 18 19:09:21 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB26FD44BD0 for ; Tue, 18 Apr 2017 19:09:21 +0000 (UTC) (envelope-from andipersti@gmail.com) Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 53F78B22 for ; Tue, 18 Apr 2017 19:09:21 +0000 (UTC) (envelope-from andipersti@gmail.com) Received: by mail-wm0-x22d.google.com with SMTP id o81so63815035wmb.1 for ; Tue, 18 Apr 2017 12:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=H2GYDizsUA62cMonKWGneIHQShdFckUdXppBIe5Ptj4=; b=d/V04VICGDJHrjawMoWKGhRqMB0s3hxVl+8aGPB3VqPOfy0t8zQPi4VJJ2p//fVxN4 jI6f89awsWPrm7tIZTSrkDx7NtO0hHM4FaSZ9sNI1+3drymqjBDHDBcfB59xjZHOMWle nZkkbdX+M/zVavE7hL3nAtJddmct1Bgi8GckVx2BKgCKzrMqkLThjit4GQTc96QjjCg1 kV7zTlEC8hJydZAKvlkmJNJ0gm8Yz3Md8dBJTqB3zZTSsqGNeM+cuyETYm3BjjW9GgQj 6odLJIdR4//Dkw2CG6RJOE2DR/TfkugCN58s9nk4nre7/e2tZCmkdF3ZC7o0I4KpnXbv t2kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=H2GYDizsUA62cMonKWGneIHQShdFckUdXppBIe5Ptj4=; b=igGPf0a7SSSI0NBOGl7a4rSKaTeou2oYZeiu6IvB/OXrvBddzsrZ93i6Df3uiJ60pm DPEPzplM3Dm4+ut/nX9SYpQkT0dnjHsCCosTrrt+Axxwwp8LpeT1TxQ+70dJhWZjwpW2 Tkg8atXjXCBIS9xg4xDe0caebJAu7vzRdnWsy2W+pi7jm3GHaq72x7fr6ci9rJsRzENk bO52fHmLDLoRE0Cwr9EPWcCVvAPCLK3p/KexXYdzi7o5qZtHrRquWp9uRy1Ple6hO5zO gMAbiWBLrOYveyt1UJ5eQ8ssJBvzD7rVOQt50Y4gF1mn1R3JwowJSVjEp0Zb2hH7PCBU jEow== X-Gm-Message-State: AN3rC/69uJTWZ/NtqRDoSiUr7xH4g/WAee9Hqv3RHDuHUcSYW0IimSyo 9alu1NAMymOFwAgv X-Received: by 10.28.156.13 with SMTP id f13mr14434763wme.44.1492542559337; Tue, 18 Apr 2017 12:09:19 -0700 (PDT) Received: from [192.168.178.25] (91-119-212-211.dsl.dynamic.surfer.at. [91.119.212.211]) by smtp.googlemail.com with ESMTPSA id h20sm516051wmd.29.2017.04.18.12.09.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Apr 2017 12:09:18 -0700 (PDT) Subject: Re: awk help From: Andreas Perstinger To: freebsd-questions@freebsd.org References: <58F25A01.1060208@gmail.com> <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org> <58F4CD14.7090008@gmail.com> <58F53EEA.2030206@gmail.com> <7b381f8f-e2a5-26ea-075e-96ae35efb25d@rogers.com> <58F61027.3090100@gmail.com> Message-ID: Date: Tue, 18 Apr 2017 21:09:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: de_AT Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Apr 2017 19:09:21 -0000 (Sorry for messing up parts of the quoting in my former mail.) On 2017-04-18 19:40, Andreas Perstinger wrote: > I think awk is the better tool for your task but you could still > simplify your shell script a little bit: After hitting the send button I realized that there is a simpler solution using a classical Unix pipe: #!/bin/sh added_date="`date +%Y%m%d`" hits_rpt="hits_rpt" hits_new="hits.yes" hits_no="hits.no" truncate -s 0 $hits_rpt $hits_new $hits_no ippool -l -d -m probing_ips > $hits_rpt 2> /dev/null tail -n +4 $hits_rpt | # start at 4th line paste - - | # join two consecutive lines sed -e 's:^ *::' -e 's:/32::' | # remove spaces at the beginning # and "/32" suffix from IP address cut -w -f 2,4 | # extract IP and Hits from combined line # (at 2nd and 4th field) while read ip hits # read IP and Hits from each line do # and do your work if [ "$hits" -gt 0 ]; then echo "$added_date ${ip};" >> $hits_new fi echo "$hits ${ip};" >> $hits_no done exit 0 If the "ippool" uses tabs in the output just add "tr '\t' ' '" between the "paste" and "sed" step. Bye, Andreas