From owner-freebsd-questions@freebsd.org Sat Apr 15 18:01:35 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 D7806D3F7CD for ; Sat, 15 Apr 2017 18:01:35 +0000 (UTC) (envelope-from jktrigg@gmail.com) Received: from mail-qk0-x22c.google.com (mail-qk0-x22c.google.com [IPv6:2607:f8b0:400d:c09::22c]) (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 8FD581131 for ; Sat, 15 Apr 2017 18:01:35 +0000 (UTC) (envelope-from jktrigg@gmail.com) Received: by mail-qk0-x22c.google.com with SMTP id f133so84010584qke.2 for ; Sat, 15 Apr 2017 11:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=gHBErS97x/R9pBGCbi/c58SDqDCMtq3KHnWYcLQSnGA=; b=Fad79HbT42wbyO39R530VKuntsejoptTi03MW/kKxrC14eW1HXkiawDXiw1MmMpNoa u875EdeX88KuUoPA3LxCSs2e+HOy7LIGH2B8ak5B5Vz4ELy+6tFxBPg1YaqZ2RHCSoyi 2xZGkSGytFqlk/82LJHbkBj09Dr2Sg/Xe/IEbtxExAzsCf6TdKP8KcBwJfGgKkFrSgD2 i84+tM5Owy7YBT9fCXAad+pJ5qccozFF9Qi2R7e0FRjCzhtYRgktlZY5ZEyNuX6+iQVp /UUA88Fc4ZS65BpP3N2X8RD4Qi13n9Dn8MKjXnhGiIfDHBseaI6Sj4Usil4Wrick1VGV 7mTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=gHBErS97x/R9pBGCbi/c58SDqDCMtq3KHnWYcLQSnGA=; b=qVduURk/KeyD7AErtKkE+S7JxrpiW8WbtWlIKHmStXGO+HiQUIxkXkpSwlmgZikRNc K1Fhj0LMg7mHY4fj4Z6LO37l8jMsOl23Ian+6h17ZAkMOPSetGY+oUPSoBgcANLQxl4M +fG+qV+CBvsZsV8x15WtPHmG1gy9R7aPU3AwgKKX4+BsyFtXZAv2cp8fOJCFCU2AoXQ3 bSZEJJBnxMorlpJydjundEepJr9Sos4z2mHJpLo+rSbzj515ieKIefWkWz8CZBp8gWl4 HHkr2GyZTDgZNXbziH7UPcCAxRbaWzLvN9D9QEWClGnj1iT8sXvaDzYeu201oD1LlMo/ Hs7Q== X-Gm-Message-State: AN3rC/7tOtvP8Yw4YQqWl6qZZ94NIxlQN2hls7lY/Y+BhKs+b5XC5/nh xqjUQtr7ei7OH+Ix+b8= X-Received: by 10.55.221.20 with SMTP id n20mr2629757qki.15.1492279294448; Sat, 15 Apr 2017 11:01:34 -0700 (PDT) Received: from [192.168.2.3] (c-73-132-2-239.hsd1.va.comcast.net. [73.132.2.239]) by smtp.googlemail.com with ESMTPSA id a2sm3541872qte.64.2017.04.15.11.01.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 15 Apr 2017 11:01:32 -0700 (PDT) Sender: Jim Trigg Date: Sat, 15 Apr 2017 13:59:30 -0400 User-Agent: K-9 Mail for Android In-Reply-To: <58F25A01.1060208@gmail.com> References: <58F25A01.1060208@gmail.com> MIME-Version: 1.0 Subject: Re: awk help To: freebsd-questions@freebsd.org From: Jim Trigg Message-ID: <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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: Sat, 15 Apr 2017 18:01:35 -0000 /^Address/ { address =3D $2; got_address =3D 1; } /^ Hits/ { if (got_address) { hits =3D $2; if (hits) { [Do what's needed with address and hits] got_address =3D 0; } else { [Handle error condition of hits without addre= ss] } } Jim On April 15, 2017 1:36:01 PM EDT, Ernie Luzar wrote= : >Hello list; > >Can not figure how to process 2 lines as a single line=2E >I have this file=2E > >poollist: opts =3D 0x2 >Name: test Role: ipf References: 2 Hits: 0 > Nodes Starting at 0xc9fd4800 > Address: 1=2E11=2E244=2E65/32 > Hits 0 Bytes 0 Name Ref 2 > Address: 1=2E163=2E113=2E139/32 > Hits 0 Bytes 0 Name Ref 2 > Address: 1=2E163=2E139=2E214/32 > Hits 0 Bytes 0 Name Ref 2 > Address: 1=2E173=2E51=2E202/32 > Hits 0 Bytes 0 Name Ref 2 > Address: 1=2E175=2E164=2E129/32 > Hits 0 Bytes 0 Name Ref 2 > Address: 99=2E197=2E14=2E34/32 > Hits 0 Bytes 0 Name Ref 2 > >The Address line and the Hits line makes a pair=2E > >For any pair that hits is greater than zero >output file with ip address with ; sufix instead of /32 and >hit value in fixed position=2E > >I can't figure out how to code awk to process the 2 lines as a pair=2E > >All ready searched the online awk references and could not find an=20 >example=2E Any pointers would sure help=2E > >Thanks >_______________________________________________ >freebsd-questions@freebsd=2Eorg mailing list >https://lists=2Efreebsd=2Eorg/mailman/listinfo/freebsd-questions >To unsubscribe, send any mail to >"freebsd-questions-unsubscribe@freebsd=2Eorg" --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E From owner-freebsd-questions@freebsd.org Sat Apr 15 18:35:13 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 A6895D3F471 for ; Sat, 15 Apr 2017 18:35:13 +0000 (UTC) (envelope-from tdemers7@gmail.com) Received: from mail-lf0-x236.google.com (mail-lf0-x236.google.com [IPv6:2a00:1450:4010:c07::236]) (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 19D529E6 for ; Sat, 15 Apr 2017 18:35:13 +0000 (UTC) (envelope-from tdemers7@gmail.com) Received: by mail-lf0-x236.google.com with SMTP id 88so5224755lfr.0 for ; Sat, 15 Apr 2017 11:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=a5zM532uhPYGRa0XEuuNqSR+v/Vm8R4LWotM2dTU2HQ=; b=tCfGgIU1FZTdLqM2uVUBsr1U4Xes1/Va5GxQy/WZFWNfJcD/jeko07GYIvNJLdwe14 MWq+41VmCAnzaeVJJEG4GL9mc8fFSQ/FP1hs+CrZeUnbPk2qTk9HwFE2gL+I+QQLt5e/ 4tUrl6lRPVhwnFEG4cV4sqcvnnKYTJpaLB8IVZBFhNCKa+c0KdVcRNGX2KyCeR8iRNp6 NzOvnzc0ACCemzDfVyw/5Ln9KITSia/qmnWpt6dbGGNZHmFLviEjsihjJmryp3R9WwBY pi+PMz9BKJvRc4lzF23eVmQuFuqzRDInr6sLchAwe1yonKHCMetjsUPNpztHZUJLiYN4 LnDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=a5zM532uhPYGRa0XEuuNqSR+v/Vm8R4LWotM2dTU2HQ=; b=sHQOG1JQarNmORqyKbg/n+v2UdtXGDZw6/m/5WaoYj/QJ4LlfmrVfS2iGDs7Rb7jYA 21TQXkdVYdFSQJWmHe1PhZTvyHdzH5+fXeippgqhD63VTJORbxKJR4Gi2sokxwoEwZgH t/AMEX98zJYX0a/lFl9TyfmnMZGdszGdScnMQPxWzhNXoM2iJwGxEZ75xa4nsFqqt0JG xNESUEnbAC9tz5ay2qKrVkC50cLp6guIBfoGoKNydbYw2cFZbrb3/ewvpiT8fk5Ja88T H7vcudNAKD+Dz5+ABSNtlz8D9KOudDHMH5SpjK5LLbEvUbE4vfKDXsfhV75Lt2Zq8pJf mZTg== X-Gm-Message-State: AN3rC/5dF13EQ61bBGlllylxc8sDT9fHo+/Udpx14JbIi/WjxjvnO5uh opp0xOnJRJWuiCcoC3dbkofcjmskxxXw X-Received: by 10.25.218.10 with SMTP id r10mr1025921lfg.123.1492281310094; Sat, 15 Apr 2017 11:35:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.205.4 with HTTP; Sat, 15 Apr 2017 11:35:09 -0700 (PDT) In-Reply-To: <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org> References: <58F25A01.1060208@gmail.com> <7951DF71-5CD3-4B53-9CB4-13CAA8945983@huiekin.org> From: Therese Demers Date: Sat, 15 Apr 2017 11:35:09 -0700 Message-ID: Subject: Re: awk help To: Jim Trigg Cc: freebsd-questions@freebsd.org Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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: Sat, 15 Apr 2017 18:35:13 -0000 Hi Ernie! I'm not sure if this will help you, but here's an idea: I created a file called "testforernie": $ cat testforernie Address: 1.11.244.65/32 Hits 0 Bytes 0 Name Ref 2 Address: 1.163.113.139/32 Hits 0 Bytes 0 Name Ref 2 Address: 1.163.139.214/32 Hits 0 Bytes 0 Name Ref 2 Address: 1.173.51.202/32 Hits 0 Bytes 0 Name Ref 2 Address: 1.175.164.129/32 Hits 0 Bytes 0 Name Ref 2 Address: 99.197.14.34/32 Hits 0 Bytes 0 Name Ref 2 $ cat testforernie | awk '{print}' ORS='' | sed 's%Address:%JellybeansAddress%g' | sed 's/Jellybeans/\'$'\n/g' | sed '/^$/d' Address 1.11.244.65/32 Hits 0 Bytes 0 Name Ref 2 Address 1.163.113.139/32 Hits 0 Bytes 0 Name Ref 2 Address 1.163.139.214/32 Hits 0 Bytes 0 Name Ref 2 Address 1.173.51.202/32 Hits 0 Bytes 0 Name Ref 2 Address 1.175.164.129/32 Hits 0 Bytes 0 Name Ref 2 Address 99.197.14.34/32 Hits 0 Bytes 0 Name Ref 2 So if you wanted to get a pair containing the address and number of hits you could do something like: $ cat testforernie | awk '{print}' ORS='' | sed 's%Address:%JellybeansAddress%g' | sed 's/Jellybeans/\'$'\n/g' | sed '/^$/d' | awk '{print $2,$4}' 1.11.244.65/32 0 1.163.113.139/32 0 1.163.139.214/32 0 1.173.51.202/32 0 1.175.164.129/32 0 99.197.14.34/32 0 Here's an explanation: The "awk '{print}' ORS='' part turns all the output into one line. The "sed 's%Address:%JellybeansAddress%g'" part just makes a delimeter that you can use to create to create a new line with (Jellybeans). The "sed 's/Jellybeans/\'$'\n/g'" part substitutes the pattern "Jellybeans" with a new line. And the "sed '/^$/d'" part gets rid of that empty line (The first instance of Jellybeans that was substituted for a new line). Hope this helps you! :) -Therese On Sat, Apr 15, 2017 at 10:59 AM, Jim Trigg wrote: > /^Address/ { address = $2; got_address = 1; } > /^ Hits/ { if (got_address) { > hits = $2; > if (hits) { > [Do what's needed with address and hits] > got_address = 0; > } else { > [Handle error condition of hits without > address] > } > } > > Jim > > On April 15, 2017 1:36:01 PM EDT, Ernie Luzar wrote: > >Hello list; > > > >Can not figure how to process 2 lines as a single line. > >I have this file. > > > >poollist: opts = 0x2 > >Name: test Role: ipf References: 2 Hits: 0 > > Nodes Starting at 0xc9fd4800 > > Address: 1.11.244.65/32 > > Hits 0 Bytes 0 Name Ref 2 > > Address: 1.163.113.139/32 > > Hits 0 Bytes 0 Name Ref 2 > > Address: 1.163.139.214/32 > > Hits 0 Bytes 0 Name Ref 2 > > Address: 1.173.51.202/32 > > Hits 0 Bytes 0 Name Ref 2 > > Address: 1.175.164.129/32 > > Hits 0 Bytes 0 Name Ref 2 > > Address: 99.197.14.34/32 > > Hits 0 Bytes 0 Name Ref 2 > > > >The Address line and the Hits line makes a pair. > > > >For any pair that hits is greater than zero > >output file with ip address with ; sufix instead of /32 and > >hit value in fixed position. > > > >I can't figure out how to code awk to process the 2 lines as a pair. > > > >All ready searched the online awk references and could not find an > >example. Any pointers would sure help. > > > >Thanks > >_______________________________________________ > >freebsd-questions@freebsd.org mailing list > >https://lists.freebsd.org/mailman/listinfo/freebsd-questions > >To unsubscribe, send any mail to > >"freebsd-questions-unsubscribe@freebsd.org" > > -- > Sent from my Android device with K-9 Mail. Please excuse my brevity. > _______________________________________________ > freebsd-questions@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions- > unsubscribe@freebsd.org" >