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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help with scripting. I a tex 2

Status
Not open for further replies.

nguyenb9

Technical User
Apr 1, 2003
55
US
I need help with scripting. I have a text file look like below and I want to write a script to take the phone number where the qdn and pasted to DN: TYPE: OPTION: etc... Please see the example below.

----------------------------------------------------------
>qdn 7134078799
----------------------------------------------------------
DN: 4078799 (PORTED-IN)
TYPE: VIRTUAL DIRECTORY NUMBER
OPTIONS: NONE
----------------------------------------------------------
>qdn 8327787152
----------------------------------------------------------
DN: 7787152 (PORTED-IN)
TYPE: SINGLE PARTY LINE
SNPA: 832 SIG: DT LNATTIDX: 52
LINE EQUIPMENT NUMBER: CB06 19 0 01 09
LINE CLASS CODE: 1FR
IBN TYPE: STATION
CUSTGRP: RESGRP SUBGRP: 0 NCOS: 52
LINE TREATMENT GROUP: 52
CARDCODE: RDTICB GND: N PADGRP: STDLN BNV: NL MNO: N
PM NODE NUMBER : 434
PM TERMINAL NUMBER : 9
OPTIONS:
COD DGT PIC 5737 Y LPIC 5737 Y
RES OPTIONS:
COT AMA
OFFICE OPTIONS:
AIN AINGRP
----------------------------------------------------

>qdn 7134078799
-------------------------------------------------------------------------------
7134078799 DN: 4078799 (PORTED-IN)
7134078799 TYPE: VIRTUAL DIRECTORY NUMBER
7134078799 OPTIONS: NONE
---------------------------------------------------------
>qdn 8327787152
----------------------------------------------------------
8327787152 DN: 7787152 (PORTED-IN)
8327787152 TYPE: SINGLE PARTY LINE
8327787152 SNPA: 832 SIG: DT LNATTIDX: 52
8327787152 LINE EQUIPMENT NUMBER: CB06 19 0 01 09
8327787152 LINE CLASS CODE: 1FR
8327787152 IBN TYPE: STATION
8327787152 CUSTGRP: RESGRP SUBGRP: 0 NCOS: 52
8327787152 INE TREATMENT GROUP: 52
8327787152 CARDCODE: RDTICB GND: N PADGRP: STDLN BNV: 8327787152 NL MNO: N
8327787152 PM NODE NUMBER : 434
8327787152 M TERMINAL NUMBER : 9
8327787152 PTIONS:
8327787152 COD DGT PIC 5737 Y LPIC 5737 Y
8327787152 RES OPTIONS:
8327787152 OT AMA
8327787152 OFFICE OPTIONS:
A8327787152 IN AINGRP

I know how to write scripts, but this one little tough for me.

Thanks for your help.
Bao
 
I don't understand what you want. Is the data you posted the input file? If it is, post an example of the oputput you want. CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
This is the input file:
---------------------------------------------------------
>qdn 7134078799
----------------------------------------------------------
DN: 4078799 (PORTED-IN)
TYPE: VIRTUAL DIRECTORY NUMBER
OPTIONS: NONE
----------------------------------------------------------
>qdn 8327787152
----------------------------------------------------------
DN: 7787152 (PORTED-IN)
TYPE: SINGLE PARTY LINE
SNPA: 832 SIG: DT LNATTIDX: 52
LINE EQUIPMENT NUMBER: CB06 19 0 01 09
LINE CLASS CODE: 1FR
IBN TYPE: STATION
CUSTGRP: RESGRP SUBGRP: 0 NCOS: 52
LINE TREATMENT GROUP: 52
CARDCODE: RDTICB GND: N PADGRP: STDLN BNV: NL MNO: N
PM NODE NUMBER : 434
PM TERMINAL NUMBER : 9
OPTIONS:
COD DGT PIC 5737 Y LPIC 5737 Y
RES OPTIONS:
COT AMA
OFFICE OPTIONS:
AIN AINGRP
----------------------------------------------------

This is the output file suppose to look like!
---------------------------------------------------------
>qdn 7134078799
---------------------------------------------------------
7134078799 DN: 4078799 (PORTED-IN)
7134078799 TYPE: VIRTUAL DIRECTORY NUMBER
7134078799 OPTIONS: NONE
---------------------------------------------------------
>qdn 8327787152
----------------------------------------------------------
8327787152 DN: 7787152 (PORTED-IN)
8327787152 TYPE: SINGLE PARTY LINE
8327787152 SNPA: 832 SIG: DT LNATTIDX: 52
8327787152 LINE EQUIPMENT NUMBER: CB06 19 0 01 09
8327787152 LINE CLASS CODE: 1FR
8327787152 IBN TYPE: STATION
8327787152 CUSTGRP: RESGRP SUBGRP: 0 NCOS: 52
8327787152 INE TREATMENT GROUP: 52
8327787152 CARDCODE: RDTICB GND: N PADGRP: STDLN BNV: 8327787152 NL MNO: N
8327787152 PM NODE NUMBER : 434
8327787152 M TERMINAL NUMBER : 9
8327787152 PTIONS:
8327787152 COD DGT PIC 5737 Y LPIC 5737 Y
8327787152 RES OPTIONS:
8327787152 OT AMA
8327787152 OFFICE OPTIONS:
8327787152 IN AINGRP

Thanks
 
I think this will do what you want

awk -f ng.awk infile > outfile

# ------ ng.awk ------
{
if ($1 == ">qdn") {
num = $2 " "
print
next
}
if ($0 !~ /^-----------/) $0 = num $0
print
} CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Can you please explain the script. What is "ng.awk"?

Thanks
 

nawk -f input.awk input.txt

#------------------- input.awk
BEGIN {
PAT_qdn=">qdn"
PAT_div="^[-]+$"
}

$0 ~ PAT_div { print; next}
$1 == PAT_qdn { gdn=$2; print; next}

{ $0 = gdn FS $0; print }
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top