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!

range records

Status
Not open for further replies.

malpa

Technical User
Feb 8, 2004
122
CO
hi

I have this file. I want to obtain blocks of lines, between those registers, which first field is "DN".

The first step is capture the first line that contain # OFC=564 #.

In Addition, I need to adjust this programm to print the last records.

my programm l.awk

function Imprimir(k,contador,office )
{
for ( j=1;j<=contador-1;j++){
if (k[j] ~/OFC/){ split(k[j],g,"="); office=g[3]}
print j"-"office"-"k[j]
}
print fin
}

BEGIN{FS=" ";band=0}
$(NF-1)~/OFC/ && band==0 { split($(NF-1),a,"="); oficina=a[2];print $0;band=1 }
$1=="DN",$1=="AMP"{
if ($(NF-1)~/OFC/){ split($(NF-1),a,"="); oficina=a[2]}
b[++cont]=$0
#print cont"-"b[cont]
if ( b[cont] ~ /AMP/ ) { Imprimir(b,cont,oficina ) ;cont=0 }
}



file.txt


NO PROCESADO POR EOC
DN-LNO,LEN,ABB-LTN,LC-DN,RC,AC
10,12,5,11,5,4
6,0
1,DN,1,MS,1,,
COMANDO ACEPTADO
<
# OFC=564 #
DN LEN ABB LC RC AC IC CCLS PCLS AMP
0031 EL=05220943 000201010 005 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=05220941 N=5640029
002 EL=05220722 N=5640300
003 EL=05220932 N=5640027
004 EL=05220770 N=5640311
DN LEN ABB LC RC AC IC CCLS PCLS AMP
0112 EL=01011261 000201010 004 002 M
CLASE DE SERVICIO
SC(0) = Q
INFORMACION DE TRANSFERENCIA DE LLAMADA SIN CONTESTACION
FN=5810001 FT=30
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=564 #
001 EL=01011271 N=5640118
002 EL=01011150 N=5640135
003 EL=01011161 N=5640137
DN LEN ABB LC RC AC IC CCLS PCLS AMP
0788 EL=00320551 000201010 004 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=00320543 N=5640515
002 EL=00320571 N=5640514
003 EL=00320570 N=5640513
004 EL=00320563 N=5640512
005 EL=00320502 N=5640511
# OFC=564 #
006 EL=00320533 N=5640510
007 EL=00320532 N=5640509
008 EL=00320531 N=5640508
009 EL=00311361 N=5640516
DN LEN ABB LC RC AC IC CCLS PCLS AMP
3066 EL=05220341 0040 000201010 000 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=05220541 N=5643063
002 EL=05220412 N=5643064
003 EL=05220350 N=5643065
004 EL=05220621 N=5643062
DN LEN ABB LC RC AC IC CCLS PCLS AMP
4552 EL=05211160 000201010 005 002 M
CLASE DE SERVICIO
SC(0) = E
RC-CONTRASENA KN=1137
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=564 #
001 EL=05211412 N=5644852
002 EL=05211230 N=5644813
DN LEN ABB LC RC AC IC CCLS PCLS AMP
4818 EL=03210623 000201010 018 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=03200202 N=5644745
002 EL=03230270 N=5637678
DN LEN ABB LC RC AC IC CCLS PCLS AMP
5630 EL=00021272 000201010 008 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=564 #
001 EL=00030113 N=5647184
002 EL=00030123 N=5647223
003 EL=00030153 N=5647983
DN LEN ABB LC RC AC IC CCLS PCLS AMP
6438 EL=00310633 000201010 017 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
DN LEN ABB LC RC AC IC CCLS PCLS AMP
6464 EL=02401421 0040 000201010 000 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=564 #
001 EL=02410033 N=5641049
002 EL=02410011 N=5630210
003 EL=02400200 N=5642547
004 EL=02400223 N=5642625
# OFC=563 #
DN LEN ABB LC RC AC IC CCLS PCLS AMP
0200 EL=01021211 000201010 008 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=01021242 N=5647094
002 EL=01010873 N=5647166
003 EL=01010901 N=5647140
DN LEN ABB LC RC AC IC CCLS PCLS AMP
2051 EL=01010800 000201010 017 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=563 #
001 EL=01011202 N=5655483
002 EL=01011042 N=5655281
003 EL=01020853 N=5656378
DN LEN ABB LC RC AC IC CCLS PCLS AMP
3701 EL=01010852 000201010 006 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=01011001 N=5633720
002 EL=01021413 N=5633719
003 EL=01021370 N=5633718
004 EL=01021351 N=5633717
005 EL=01021540 N=5633715
# OFC=563 #
006 EL=01021532 N=5633714
007 EL=01021331 N=5633713
008 EL=01010811 N=5630869
009 EL=01011021 N=5633722
010 EL=01021521 N=5633712
011 EL=01010803 N=5633704
012 EL=01010823 N=5633706
013 EL=01010833 N=5633707
014 EL=01010843 N=5633708
015 EL=01010813 N=5633705
016 EL=01010872 N=5633703
017 EL=01021511 N=5633711
018 EL=01021502 N=5633710
# OFC=563 #
019 EL=01011011 N=5633721
DN LEN ABB LC RC AC IC CCLS PCLS AMP
6000 EL=05210911 000201010 005 002 M
CLASE DE SERVICIO
SC(0) = E
RC-CONTRASENA KN=3498
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=05211350 N=5633346
002 EL=05211430 N=5633498
003 EL=05211561 N=5633646
DN LEN ABB LC RC AC IC CCLS PCLS AMP
6383 EL=01331332 000201010 005 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=563 #
001 EL=04430030 N=5636624
002 EL=04430023 N=5636623
003 EL=04430003 N=5636611
004 EL=01331342 N=5636565
005 EL=01331452 N=5636401
006 EL=01331410 N=5636397
# OFC=565 #
DN LEN ABB LC RC AC IC CCLS PCLS AMP
0987 EL=02400612 0040 000201010 000 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=02400570 N=5650765
# OFC=565 #
002 EL=02400740 N=5645465
DN LEN ABB LC RC AC IC CCLS PCLS AMP
1690 EL=01011131 000201010 008 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=01021212 N=5653890
002 EL=01011053 N=5656176
DN LEN ABB LC RC AC IC CCLS PCLS AMP
3944 EL=04210852 0040 000201010 000 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=565 #
001 EL=04211002 N=5648110
002 EL=04211011 N=5648112
003 EL=04211572 N=5648117
004 EL=04220212 N=5648122
005 EL=04211160 N=5648113
006 EL=04220501 N=5643977
DN LEN ABB LC RC AC IC CCLS PCLS AMP
4180 EL=01010820 000201010 017 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=01020923 N=5656333
DN LEN ABB LC RC AC IC CCLS PCLS AMP
5058 EL=00300500 000201010 017 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
# OFC=565 #
001 EL=00300521 N=5655185
DN LEN ABB LC RC AC IC CCLS PCLS AMP
5554 EL=01031072 0040 000201010 000 002 M
LISTA DE MULTIBUSQUEDA
INDICADOR DE BUSQUEDA HC=1
LEN LTN DN TMB STP
001 EL=01031073 N=5656426
002 EL=01031120 N=5656427
003 EL=01031170 N=5656428
004 EL=01031203 N=5656429
005 EL=01031210 N=5656436
006 EL=01031231 N=5656439
007 EL=01031272 N=5656440
# OFC=565 #
008 EL=01031312 N=5656445
# OFC=596 #
# OFC=920 #
TOTAL 00020
27 OCT 09 MAR 21:41 ASTURIAS MAT21




output.txt

# OFC=564 #

1-564- 0031 EL=05220943 000201010 005 002 M
2-564- LISTA DE MULTIBUSQUEDA
3-564- INDICADOR DE BUSQUEDA HC=1
4-564- LEN LTN DN TMB STP
5-564- 001 EL=05220941 N=5640029
6-564- 002 EL=05220722 N=5640300
7-564- 003 EL=05220932 N=5640027
8-564- 004 EL=05220770 N=5640311

1-564- 0112 EL=01011261 000201010 004 002 M
2-564- CLASE DE SERVICIO
3-564- SC(0) = Q
4-564- INFORMACION DE TRANSFERENCIA DE LLAMADA SIN CONTESTACION
5-564- FN=5810001 FT=30
6-564- LISTA DE MULTIBUSQUEDA
7-564- INDICADOR DE BUSQUEDA HC=1
8-564- LEN LTN DN TMB STP
9-- # OFC=564 #
10-- 001 EL=01011271 N=5640118
11-- 002 EL=01011150 N=5640135
12-- 003 EL=01011161 N=5640137

1-564- 0788 EL=00320551 000201010 004 002 M
2-564- LISTA DE MULTIBUSQUEDA
3-564- INDICADOR DE BUSQUEDA HC=1
4-564- LEN LTN DN TMB STP
5-564- 001 EL=00320543 N=5640515
6-564- 002 EL=00320571 N=5640514
7-564- 003 EL=00320570 N=5640513
8-564- 004 EL=00320563 N=5640512
9-564- 005 EL=00320502 N=5640511
10-- # OFC=564 #
11-- 006 EL=00320533 N=5640510
12-- 007 EL=00320532 N=5640509
13-- 008 EL=00320531 N=5640508
14-- 009 EL=00311361 N=5640516

1-564- 3066 EL=05220341 0040 000201010 000 002 M
2-564- LISTA DE MULTIBUSQUEDA
3-564- INDICADOR DE BUSQUEDA HC=1
4-564- LEN LTN DN TMB STP
5-564- 001 EL=05220541 N=5643063
6-564- 002 EL=05220412 N=5643064
7-564- 003 EL=05220350 N=5643065
8-564- 004 EL=05220621 N=5643062

1-564- 4552 EL=05211160 000201010 005 002 M
2-564- CLASE DE SERVICIO
3-564- SC(0) = E
4-564- RC-CONTRASENA KN=1137
5-564- LISTA DE MULTIBUSQUEDA
6-564- INDICADOR DE BUSQUEDA HC=1
7-564- LEN LTN DN TMB STP
8-- # OFC=564 #
9-- 001 EL=05211412 N=5644852
10-- 002 EL=05211230 N=5644813

1-564- 4818 EL=03210623 000201010 018 002 M
2-564- LISTA DE MULTIBUSQUEDA
3-564- INDICADOR DE BUSQUEDA HC=1
4-564- LEN LTN DN TMB STP
5-564- 001 EL=03200202 N=5644745
6-564- 002 EL=03230270 N=5637678

1-564- 5630 EL=00021272 000201010 008 002 M
2-564- LISTA DE MULTIBUSQUEDA
3-564- INDICADOR DE BUSQUEDA HC=1
4-564- LEN LTN DN TMB STP
5-- # OFC=564 #
6-- 001 EL=00030113 N=5647184
7-- 002 EL=00030123 N=5647223
8-- 003 EL=00030153 N=5647983

1-564- 6438 EL=00310633 000201010 017 002 M
2-564- LISTA DE MULTIBUSQUEDA
3-564- INDICADOR DE BUSQUEDA HC=1
4-564- LEN LTN DN TMB STP

1-563- 6464 EL=02401421 0040 000201010 000 002 M
2-563- LISTA DE MULTIBUSQUEDA
3-563- INDICADOR DE BUSQUEDA HC=1
4-563- LEN LTN DN TMB STP
5-- # OFC=564 #
6-- 001 EL=02410033 N=5641049
7-- 002 EL=02410011 N=5630210
8-- 003 EL=02400200 N=5642547
9-- 004 EL=02400223 N=5642625
10-- # OFC=563 #

1-563- 0200 EL=01021211 000201010 008 002 M
2-563- LISTA DE MULTIBUSQUEDA
3-563- INDICADOR DE BUSQUEDA HC=1
4-563- LEN LTN DN TMB STP
5-563- 001 EL=01021242 N=5647094
6-563- 002 EL=01010873 N=5647166
7-563- 003 EL=01010901 N=5647140

1-563- 2051 EL=01010800 000201010 017 002 M
2-563- LISTA DE MULTIBUSQUEDA
3-563- INDICADOR DE BUSQUEDA HC=1
4-563- LEN LTN DN TMB STP
5-- # OFC=563 #
6-- 001 EL=01011202 N=5655483
7-- 002 EL=01011042 N=5655281
8-- 003 EL=01020853 N=5656378

1-563- 3701 EL=01010852 000201010 006 002 M
2-563- LISTA DE MULTIBUSQUEDA
3-563- INDICADOR DE BUSQUEDA HC=1
4-563- LEN LTN DN TMB STP
5-563- 001 EL=01011001 N=5633720
6-563- 002 EL=01021413 N=5633719
7-563- 003 EL=01021370 N=5633718
8-563- 004 EL=01021351 N=5633717
9-563- 005 EL=01021540 N=5633715
10-- # OFC=563 #
11-- 006 EL=01021532 N=5633714
12-- 007 EL=01021331 N=5633713
13-- 008 EL=01010811 N=5630869
14-- 009 EL=01011021 N=5633722
15-- 010 EL=01021521 N=5633712
16-- 011 EL=01010803 N=5633704
17-- 012 EL=01010823 N=5633706
18-- 013 EL=01010833 N=5633707
19-- 014 EL=01010843 N=5633708
20-- 015 EL=01010813 N=5633705
21-- 016 EL=01010872 N=5633703
22-- 017 EL=01021511 N=5633711
23-- 018 EL=01021502 N=5633710
24-- # OFC=563 #
25-- 019 EL=01011011 N=5633721

1-563- 6000 EL=05210911 000201010 005 002 M
2-563- CLASE DE SERVICIO
3-563- SC(0) = E
4-563- RC-CONTRASENA KN=3498
5-563- LISTA DE MULTIBUSQUEDA
6-563- INDICADOR DE BUSQUEDA HC=1
7-563- LEN LTN DN TMB STP
8-563- 001 EL=05211350 N=5633346
9-563- 002 EL=05211430 N=5633498
10-563- 003 EL=05211561 N=5633646

1-565- 6383 EL=01331332 000201010 005 002 M
2-565- LISTA DE MULTIBUSQUEDA
3-565- INDICADOR DE BUSQUEDA HC=1
4-565- LEN LTN DN TMB STP
5-- # OFC=563 #
6-- 001 EL=04430030 N=5636624
7-- 002 EL=04430023 N=5636623
8-- 003 EL=04430003 N=5636611
9-- 004 EL=01331342 N=5636565
10-- 005 EL=01331452 N=5636401
11-- 006 EL=01331410 N=5636397
12-- # OFC=565 #

1-565- 0987 EL=02400612 0040 000201010 000 002 M
2-565- LISTA DE MULTIBUSQUEDA
3-565- INDICADOR DE BUSQUEDA HC=1
4-565- LEN LTN DN TMB STP
5-565- 001 EL=02400570 N=5650765
6-- # OFC=565 #
7-- 002 EL=02400740 N=5645465

1-565- 1690 EL=01011131 000201010 008 002 M
2-565- LISTA DE MULTIBUSQUEDA
3-565- INDICADOR DE BUSQUEDA HC=1
4-565- LEN LTN DN TMB STP
5-565- 001 EL=01021212 N=5653890
6-565- 002 EL=01011053 N=5656176

1-565- 3944 EL=04210852 0040 000201010 000 002 M
2-565- LISTA DE MULTIBUSQUEDA
3-565- INDICADOR DE BUSQUEDA HC=1
4-565- LEN LTN DN TMB STP
5-- # OFC=565 #
6-- 001 EL=04211002 N=5648110
7-- 002 EL=04211011 N=5648112
8-- 003 EL=04211572 N=5648117
9-- 004 EL=04220212 N=5648122
10-- 005 EL=04211160 N=5648113
11-- 006 EL=04220501 N=5643977

1-565- 4180 EL=01010820 000201010 017 002 M
2-565- LISTA DE MULTIBUSQUEDA
3-565- INDICADOR DE BUSQUEDA HC=1
4-565- LEN LTN DN TMB STP
5-565- 001 EL=01020923 N=5656333

1-565- 5058 EL=00300500 000201010 017 002 M
2-565- LISTA DE MULTIBUSQUEDA
3-565- INDICADOR DE BUSQUEDA HC=1
4-565- LEN LTN DN TMB STP
5-- # OFC=565 #
6-- 001 EL=00300521 N=5655185

thanks malpa
 
Hi

my second solution

With this programm I can to print the last records. But this solution doesn`t print the line

DN LEN ABB LC RC AC IC CCLS PCLS AMP into the all blocks.

BEGIN{band=0}
$1~/DN/ || band==0 {
print $0
getline
while ( $1!~/DN/){
print $0
getline
if ( $0~/TOTAL/ ) exit
}
print "0"
if ( $1!~/DN/) { band=1}
}
$1~/DN/ || band==1{
print $0
getline
while ( $1!~/DN/){
print $0
getline
if ( $0~/TOTAL/ ) exit
}
print "1"
if ( $1!~/DN/) { band=0}
}

Thanks malpa
 
It's hard to figure out what's wrong with your script because the requirements are not clear. The output of your second version is completely different to the output of the first version.

I experimented with the second version; I noticed that the if ( $1!~/DN/) { band=... } clause is never executed.

Also the only time it reaches the second block of code is when it falls through from the first. I would expect you to have next commands at the end of each section. I tried that too, but in that case the second clause (band==1) is never executed.

I don't understand what you are trying to with the band=0, band=1 stuff, perhaps you could try explaining it again?

Annihilannic.
 
Thanks Annihilannic.

I considered your recomendations,

A new version , but I dont know what happened with this version , because some times this programm remain in a loop.??


function Imprimir(q,contador,oficina ){
if ( contador > 1 )
{
for ( i=1;i<=contador;i++){
split(q,array," ")
if( array[3] ~ /^N/ ) {split(array[3],h,"=");oficina=substr(h[2],1,3); print oficina }
if ( array[1] ~ /^[0-9]/ && length(array[1])==3 ) { LEN=array[1]; LTN=array[2]; DN=array[3]}
print oficina "-" LEN "-" LTN "-" DN
}


}

}
BEGIN{}
$0 !~ /^[A-Z0-9<]/{
if($0~/OFC=/) { print $0;split($(NF-1),of,"="); ofi=of[2];print ofi}
p[++cont]=$0
getline
while ( $1!~/DN/){
p[++cont]=$0
getline
if ( $0~/TOTAL/ ) { p[++cont]=$0;exit}
}
Imprimir(p,cont,ofi );
ofi=ofn
cont=0
}
$1=="DN"{p[++cont]=$0}
END{
Imprimir(p,cont,ofi )
}

thanks malpa
 
hi


I had to include this sentece if ( $0~/TOTAL/ ) { p[++cont]=$0;exit}
because the programm remain in a loop.

Thanks malpa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top