Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a script to output records by #of lines per recor

Status
Not open for further replies.

Parser

MIS
Mar 3, 2008
2
US
All,
I have a couple of really huge text files to parse. Radius output logs for five services per 24 hour span. I need to drop the "Start" records and keep the "Stop" records, so I can analyze values within the "Stop" records.

Here's what the data typically looks like:

<-SAR->
RADIUS-R05|[1013126401]|2002-02-08:00:00:01|(FRI)
User-Name = &quot;USER&quot;
NAS-Identifier = xxx.xxx.xxx.xxx
NAS-Port = 20301
NAS-Port-Type = Async
Acct-Status-Type = Start
Acct-Delay-Time = 0
Acct-Session-Id = &quot;378074791&quot;
Acct-Authentic = RADIUS
Framed-Protocol = PPP
Framed-Address = xxx.xxx.xxx.xxx
<-EAR->
<-SAR->
RADIUS-R20|[1013126402]|2002-02-08:00:00:02|(FRI)
NAS-Identifier = XXX.XXX.XXX.XXX
NAS-Port = 20202
NAS-Port-Type = Async
Acct-Status-Type = Stop
Acct-Delay-Time = 0
Acct-Session-Id = &quot;352201385&quot;
Ascend-Disconnect-Cause = 10
Ascend-Connect-Progress = 31
Ascend-Data-Rate = 0
Ascend-PreSession-Time = 65
Ascend-Pre-Input-Octets = 0
Ascend-Pre-Output-Octets = 0
Ascend-Pre-Input-Packets = 0
Ascend-Pre-Output-Packets = 0
Caller-Id = &quot;XXXXXXXXXX&quot;
Client-Port-DNIS = &quot;XXXXXXX&quot;
<-EAR->

My thought was to use Sed to drop out the EAR/SAR headers, input a newline between records and then ask Awk to select only those records with NF >= 14, which would seem to drop out the &quot;Start&quot; records, and leave the &quot;Stop&quot; ones.

I've had to change that slightly, since I can't seem to substitute or insert (or append) an newline character in Sed, but I have been able to drop out the EAR/SAR in favor of a &quot;-&quot;, with the though that I can set FS = &quot;/n&quot; and RS to &quot;^-&quot;.

At this point, I'm stumped. I have never been able to come up with a selection criteria that sent only the desired records out to a file. Any thoughts?
 
Hi parser!

You can put string &quot;<-SAR->&quot; as record separator:

Code:
awk 'BEGIN { RS = &quot;<-SAR->&quot;; FS = &quot;\n&quot; }  NF > 14 { print }' inputfile

Bye!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top