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!

Grab Two Fields 1st/Last Under Text 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I was wondering if I could get some help on looking for specific text, and grabbing
only a certain range below it. My input file file# (Dont know how may there could be)
has the text DCP in it. Directly under this text there will be numbers. The
numbers may be any number from 1-24 and may or may not be in numerical order.

See example below:

RXOTX-16-3 CONFIG HOP 8 43 NO NONE
RXOTX-16-4 CONFIG 625 1 41 YES NONE
RXOTX-16-5 CONFIG HOP 3 41 NO NONE
RXOTX-16-6 CONFIG HOP 4 41 NO NONE
RXOTX-16-7 CONFIG HOP 5 41 NO NONE
RXOTX-16-8 CONFIG 633 0 41 YES NONE
RXOTX-16-9 CONFIG HOP 9 41 NO NONE
RXOTX-16-10 CONFIG HOP 10 41 NO NONE

END

<RXAPP:MO=RXOTG-16;


RADIO X-CEIVER ADMINISTRATION
ABIS PATH STATUS

MO
RXOTG-16

DEV DCP APUSAGE APSTATE
RBLT24-384 1 MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
RBLT24-385 2 MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
RBLT24-386 3 MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
RBLT24-387 4 MPLEX32 IDLE
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
RBLT24-388 5 MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
MPLEX16 SPEECH/DATA
RBLT24-389 6 MPLEX16 SPEECH/DATA

END

The word &quot;END&quot; will appear many times in the input file, but may be a reference point to
know where to stop looking. This part confuses me, so I will leave it up to whoever can
help.

All I need is to grab the first number below the DCP and the last number in the column
under the DCP text and replace the text DCP_FIRST with the first number, and DCP_SECOND
with the second number in the corresponding pre_build_h# file. (file1 with pre_build_h1
and so on) and then output to pre_build_i# (Use the number at the end of the input files,)

In the above text it would find the numbers 1 and 6. 1 would be DCP_FIRST and 6 would be
substituted for DCP_SECOND in the pre_build_h# file.

The pre_build_h# file looks like below:

RXMOI:MO=RXOTF-152,TFMODE=SA;
RXMOI:MO=RXOCON-152,DCP=64&&87;
DTBLE:DIP=223RBLT;
EXDAI:DEV=DEVICE_RANGE;
BLODE:DEV=DEVICE_RANGE;
RXAPI:MO=RXOTG-152,DEV=DEVICE_RANGE,DCP=FIRST_DCP&&SECOND_DCP;

[2thumbsup]
 
Ok moving forward I have gotten through some of this. I look in file# for RBLT which will give me all the DCP's I need.

Using the same file # for the output file is easy, after everyones help. Here is what I have so far:

#----nawktest----
BEGIN {
outputFileROOT=&quot;dcp_test_&quot;
unknownNUM=&quot;999999&quot;;
}

FNR == 1 {
if (match(FILENAME, &quot;[0-9]&quot;))
output=outputFileROOT substr(FILENAME, RSTART, RLENGTH);
else
output=outputFileROOT unknownNUM;
}

/(RBLT)/ { print >> output; }


I am now left with :

RBLT24-264 1 MPLEX16 SPEECH/DATA
RBLT24-265 2 CONC TRXC SIGNALLING 5 6 8 10
RBLT24-266 3 UNDEF IDLE
RBLT24-267 4 MPLEX16 SPEECH/DATA
RBLT24-268 5 MPLEX16 SPEECH/DATA
RBLT24-269 6 MPLEX16 SPEECH/DATA
RBLT24-270 7 UNDEF IDLE
RBLT24-271 8 UNDEF IDLE
RBLT24-272 9 UNDEF IDLE
RBLT24-273 10 MPLEX16 SPEECH/DATA
RBLT24-274 11 MPLEX16 SPEECH/DATA
RBLT24-275 12 MPLEX16 SPEECH/DATA
RBLT24-276 13 MPLEX16 SPEECH/DATA
RBLT24-277 14 MPLEX16 SPEECH/DATA
RBLT24-278 15 UNDEF IDLE
RBLT24-279 16 UNDEF IDLE
RBLT24-280 17 UNDEF IDLE
RBLT24-281 18 MPLEX16 SPEECH/DATA
RBLT24-282 19 MPLEX16 SPEECH/DATA
RBLT24-283 20 CONC CF AND TRXC
RBLT24-284 21 MPLEX16 SPEECH/DATA
RBLT24-285 22 MPLEX16 SPEECH/DATA
RBLT24-286 23 MPLEX16 SPEECH/DATA
RBLT24-287 24 MPLEX16 SPEECH/DATA

So if I could get some help, I need to grab the first number in column 1 which I believe is $1 from dcp_# and pass it to the corresponding pre_build_h# file replacing the text DCP_FIRST and then the last number in that column and replacing DCP_SECOND in pre_build_h#. I would like it output to pre_build_i#. Remember that there will be many files.

I have been running using:

nawk -f nawktest file*

Next I should most likely run as:

nawk -f nawktest2 dcp_test*
 
Has anyone had a chance to review this last part? I have been staring at it for hours and still seem to be stuck.

Beaster
 
Ok Beaster, I finally weakened. I hope this doesn't turn into another one of our marathon threads.

BEGIN {
FileROOT=&quot;pre_build_i&quot;
unknownNUM=&quot;999999&quot;;
}

FNR == 1 {
if (match(FILENAME, &quot;[0-9]&quot;)) {
n = substr(FILENAME, RSTART, RLENGTH)
output=FileROOT n
}
else
output=outputFileROOT unknownNUM
flg = 0
while ((getline a < &quot;dcp_test_&quot; n) > 0) {
split(a,b)
if (!flg) {
n1 = b[2]
flg = 1
}
n2 = b[2]
}
#print n1,n2
}

{
gsub(/FIRST_DCP/, n1, $0)
gsub(/SECOND_DCP/, n2, $0)
#print
print > output
}

Run it against pre_build_h* NOT dcp_test_*. Just out of interest, where are all these data files coming from and what happens to the output files you create? CaKiwi
 
The data files are coming from an orginal input file that houses all the cell site info for a particular region. When the sites need to be &quot;rehomed&quot; to a new switch, it takes months to prepare and write the actual DT to do these moves. Along with this, is the human factor which causes error. I am basically teaching the script where to look, grab data from different switches and put it all together, in the form of DT files that can be run very quickly and move the sites into the new switch without any error at all.

The 4 months I have spent on this will save more time than you could imagine. When I am done, I would offer the scripts to anyone in this field to use. I am making it pretty generic, so it can be used across multiple cellular networks:

GSM, TDMA, CDMA, NORTEL, NOKIA, ERICSSON, SIEMENS ect.

I do have one last portion that adds in the specific devices on the T1 for the sites, but that is next week.......

All my thanks,
Beaster
 
That's a good idea beaster.
Just make sure you don't script yourself
out of work ;)
 
Mars,
I will try not too! I have some measures in place to prevent this from happening, in a round about kind of way....Cant give out all the secrets....

:)
 
CaKiwi,
I ran it exactly like you stated and it does not replaced the text with the numbers. It just clears FIRST_DCP and SECOND_DCP when it should replace first with 1 and second with 24. Here was the final output file:

RXMOI:MO=RXOTF-152,TFMODE=SA;
RXMOI:MO=RXOCON-152,DCP=64&&87;
DTBLE:DIP=223RBLT;
EXDAI:DEV=DEVICE_RANGE;
BLODE:DEV=DEVICE_RANGE;
RXAPI:MO=RXOTG-152,DEV=DEVICE_RANGE,DCP=&&;
 
Add

print b[1],b[2],b[3]

after the split statement and uncomment the

print n1,n2

statement CaKiwi
 
Ok I set it like that and I dont think it is seeing any text in the second column below:

RBLT24-264 1 MPLEX16 SPEECH/DATA
RBLT24-265 2 CONC TRXC SIGNALLING
RBLT24-266 3 UNDEF IDLE
RBLT24-267 4 MPLEX16 SPEECH/DATA
RBLT24-268 5 MPLEX16 SPEECH/DATA
RBLT24-269 6 MPLEX16 SPEECH/DATA
RBLT24-270 7 UNDEF IDLE
RBLT24-271 8 UNDEF IDLE
RBLT24-272 9 UNDEF IDLE
RBLT24-273 10 MPLEX16 SPEECH/DATA
RBLT24-274 11 MPLEX16 SPEECH/DATA
RBLT24-275 12 MPLEX16 SPEECH/DATA
RBLT24-276 13 MPLEX16 SPEECH/DATA
RBLT24-277 14 MPLEX16 SPEECH/DATA
RBLT24-278 15 UNDEF IDLE
RBLT24-279 16 UNDEF IDLE
RBLT24-280 17 UNDEF IDLE
RBLT24-281 18 MPLEX16 SPEECH/DATA
RBLT24-282 19 MPLEX16 SPEECH/DATA
RBLT24-283 20 CONC CF AND TRXC
RBLT24-284 21 MPLEX16 SPEECH/DATA
RBLT24-285 22 MPLEX16 SPEECH/DATA
RBLT24-286 23 MPLEX16 SPEECH/DATA
RBLT24-287 24 MPLEX16 SPEECH/DATA


I looked at your script, are you splitting the first column? The text I want is in the second column where the 1-24 is.

 
Maybe the dcp_test file has tabs in it. Change the print statements to

print b[1] &quot; , &quot; b[2] &quot; , &quot; b[3]

print n1 &quot; , &quot; n2


CaKiwi
 
After doing that I get :

bham_mta@wepmas1> nawk -f nawktest2 pre_build_h*
,
,
,
bham_mta@wepmas1>
 
CaKiwi,
what character are you split-ting on? vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
It is not reading the dcp_test_1 file. Make sure that the name is correct and that the file is available. Replace the getline with

fn = &quot;dcp_test_&quot; n
print fn
while ((getline a < fn) > 0) {

CaKiwi
 
Vlad,

It should default to FS, which (by default) is spaces. CaKiwi
 
I would - call me paranoid:

dspFile=&quot;dcp_test_&quot; n

while ((getline a < dspFIle) > 0) { vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
I love the sweet smell of CaKiwi's success!!!!

That was it! I have just one last piece to work out and the entire program will be complete!

CaKiwi, I know it has been much time consuming for you to assist with this, but I really wanted to let you know that your help has been much appreciated!

When I get the formula ready to figure out what range of devices are needed on the T1, would you mind helping me work out the math using awk and replacing the text where it needs to go? That will be the very last piece I need to finish all of this.
 
Beaster - Glad it worked for you. Post the next problem when you are ready and if I can't help, I'm sure someone else will.

Vlad - I agree with your filename suggestion. My own paranoia must have abated briefly when I posted that. And remember, just because you're paranoid doesn't mean that people (or awk) are not out to get you. CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top