The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix Arithmatic operation issue , datatype issue thambi Shell Programming and Scripting 23 02-19-2008 07:19 AM
awk and sed filtering invinzin21 Shell Programming and Scripting 2 01-11-2008 03:56 AM
port filtering ujjwalmohan HP-UX 0 11-26-2007 01:18 AM
awk filtering ? varungupta UNIX for Advanced & Expert Users 4 09-17-2007 02:55 AM
word filtering mark_nsx UNIX for Dummies Questions & Answers 9 10-10-2005 03:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-29-2008
roachmmflhyr roachmmflhyr is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 1
Sed filtering issue

The problem I have is that I have 23,000 records I need to sort through to pull out LEN: XXXX XX XX XX XX and NCOS: XXX entries from so I can insert them into a database. But some of my records include TYPE: ISDN, THE DN IS UNASSIGNED, or INVALID entries in between some records and I would like them to print where they are supposed to. Here is a sample of my records:
Code:
LEN:     HOST  11 0 14 10
TYPE: SINGLE PARTY LINE
SNPA: 315
DIRECTORY NUMBER:     6320171
LINE CLASS CODE:  IBN
IBN TYPE: STATION
CUSTGRP:           KAFB     SUBGRP: 0  NCOS: 16
SIGNALLING TYPE:  DIGITONE
CARDCODE:  6X17AC    GND: N  PADGRP: ONS  BNV: NL MNO: N
PM NODE NUMBER     :    72
PM TERMINAL NUMBER :    459
OPTIONS:
3WC CLF RAG AVT PREMTBL DGT CND NOAMA CNAMD NOAMA NAME PUBLIC BLDG 3135
FUELS SPB 5406320171 CFI $ I
-------------------------------------------------------------------------------
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
THE DN IS UNASSIGNED
-------------------------------------------------------------------------------
LEN:     HOST  13 1 16 22
TYPE: SINGLE PARTY LINE
SNPA: 315
DIRECTORY NUMBER:     6320063
LINE CLASS CODE:  IBN
IBN TYPE: STATION
CUSTGRP:           KAFB     SUBGRP: 0  NCOS: 51
SIGNALLING TYPE:  DIGITONE
CARDCODE:  6X17AC    GND: N  PADGRP: ONS  BNV: NL MNO: N
PM NODE NUMBER     :    77
PM TERMINAL NUMBER :    535
OPTIONS:
3WC COD CLF RAG LNR AVT PREMTBL DGT CND NOAMA CNAMD NOAMA NAME PUBLIC BLDN
220 SPB 5056320063 CPU 0 HOST 13 1 16 22 CFI 6344266 A
-------------------------------------------------------------------------------
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
THE DN IS UNASSIGNED
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
-------------------------------------------------------------------------------
LEN:     RST3  01 0 13 14
TYPE: SINGLE PARTY LINE
SNPA: 315
DIRECTORY NUMBER:     6327103
LINE CLASS CODE:  IBN
IBN TYPE: STATION
CUSTGRP:           KAFB     SUBGRP: 0  NCOS: 13
SIGNALLING TYPE:  DIGITONE
CARDCODE:  6X17BA    GND: N  PADGRP: ONS  BNV: NL MNO: N
PM NODE NUMBER     :    107
PM TERMINAL NUMBER :    431
OPTIONS:
DTM CWT 3WC COD CLF RAG CWI LNR DGT NAME PUBLIC 7149 RM233 CFI $ I
-------------------------------------------------------------------------------
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
-------------------------------------------------------------------------------
I was using this script to do just that, but I cannot get NCOS: XXX to show up:
Code:
#/bin/bash
sed -nr "/LEN:|TYPE:\ ISDN|THE\ DN\ IS\ UNASSIGNED|INVALID/s/.*(HOST.{12}|RST1.{12}|RST2.{12}|RST3.{12}|RST4.{12}|ISDN|UNASSIGNED|INVALID).*/\1/p" FILE > NEWFILE
This script works great for pulling the LEN: XXXX XX XX XX XX and NCOS: XXX from my records.(btw I need ncos and len to be on the same line)

Code:
#!/bin/bash
sed -nr '/^LEN:/,/--------/{                           
                            /LEN:|CUST/s/.*(HOST.{12}|RST1.{12}|RST2.{12}|RST3.{12}|RST4.{12}|NCOS: [0-9][0-9]*).*/\1/p
                           }' FILE | sed -e '$!N' -e 's/\n/  /g' > NEW FILE
Any help would be greatly appreciated by my coworkers and myself considering this project is due Monday and we are only about 20% done. Thanks.
  #2 (permalink)  
Old 10-30-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Can you give us an example of the output you expect from that sample input? Also you mention TYPE: ISDN records, but didn't give them in the examples.
  #3 (permalink)  
Old 10-30-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Since it's due on Monday you've probably found a workaround by now, but I'll take a punt anyway and you can probably modify it to your requirements:

Code:
awk -F': *' '
        /LEN:/ { len=$2 }
        /NCOS:/ { ncos=$NF }
        /----/ { print len,ncos }
        /INVALID|UNASSIGNED/
' inputfile
Gives:

Code:
HOST  11 0 14 10 16
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
THE DN IS UNASSIGNED
HOST  11 0 14 10 16
HOST  13 1 16 22 51
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
THE DN IS UNASSIGNED
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
HOST  13 1 16 22 51
RST3  01 0 13 14 13
INVALID LEN SPECIFIED FOR THE QLEN COMMAND.
RST3  01 0 13 14 13
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0