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!

MARSD Can you Help? 1

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
Hi all! This post me be sorta long, so I apologize ahead of time.

Files involved:

file#
pre_build#
master_sorted

Task 1:
Begin with the first search using file# (exam: file1) and find the text RXOTG-# (exam: RXOTG-296). It may be up to 3

numerics at the end, but no more. The text in the file# where it is located to is similiar to below:

MO CELL
RXOTG-296 B00227A
B00227B
B00227C
B00227A
B00227B
B00227C

So after finding RXOTG-#, look in the file named master_sorted and compare the number at the end of RXOTG, which in this

case is 296 to the first field in the file named master_sorted (which has fields seperated by commas.) The file

master_sorted looks similiar to below:

11,11,121,100,B00055
16,16,121,100,B00058
296,96,121,100,B00345

When it finds the match 296 from file# and master_sorted field $1, grab the number in field $3 and use it instead of 296.

Meaning it will now be RXOTG-121.

So RXOTG-121 is the text we want to keep.

Finally, we want to look for the file named pre_build# (exam: pre_build1) that matches the file# we were using, and replace

the text: TG_NUM any where in the file with the text we saved RXOTG-121.
The text in the file pre_build# is exactly like below:


RXMOI:MO=RXOTG-TG_NUM,COMB=HYB,RSITE=SITE_NUMBER,SWVER=B0531R0702;
RXESI:MO=RXOTG-TG_NUM;
RXBLE:MO=RXOTG-TG_NUM;
RXMOI:MO=RXOCF-TG_NUM,TEI=TG_TEI;
RXMOC:MO=RXOCF-TG_NUM,SIG=CONC;
RXMOI:MO=RXOIS-TG_NUM;
RXMOI:MO=RXOTF-TG_NUM,TFMODE=SA;
RXMOI:MO=RXOCON-TG_NUM,DCP=64&&87;

So we would end up with the following text inside the pre_build1 file.:

RXMOI:MO=RXOTG-121,COMB=HYB,RSITE=SITE_NUMBER,SWVER=B0531R0702;
RXESI:MO=RXOTG-121;
RXBLE:MO=RXOTG-121;
RXMOI:MO=RXOCF-121,TEI=TG_TEI;
RXMOC:MO=RXOCF-121,SIG=CONC;
RXMOI:MO=RXOIS-121;
RXMOI:MO=RXOTF-121,TFMODE=SA;
RXMOI:MO=RXOCON-121,DCP=64&&87;

The script needs to keep the files named the same in order to accomplish what I need when finalized. It also needs to keep

processing until it has finished all the file# files and written to the pre_build# files. I hope this was not too confusing!

Thanks,
Beaster
 
Try this.
Code:
/^RXOTG/{
  fn = FILENAME
  sub(/^[^0-9]*/,"",fn)
  a = $1
  sub(/.*-/,"",a)
  found = 0
  while (!found && ((getline < &quot;master_sorted&quot;) > 0)) {
    split ($0,b,&quot;,&quot;)
    if (b[1] == a) found = 1
    num = b[3]
  }
  close(&quot;master_sorted&quot;)
  if (found) {
    fn1 = &quot;pre_build&quot; fn
    fn2 = &quot;pre_build_out&quot; fn
    while ((getline < fn1) > 0) {
      sub(/TG_NUM/,num,$0)
      print > fn2
    }
    close(fn1)
    close(fn2)
    nextfile
  }
}
Run it by entering

awk -f this-file file*

I'm hoping it's worth another beer credit. CaKiwi
 
Hi CaKiwi! Good to hear from you! You get 10 BEER credits for this one if we get it to do it!

It looks good, although I am getting an error:

bham_mta@wepmas1> nawk -f nawk_test1 file*
nawk: illegal statement
input record number 10, file file1
source line number 22

 
As I feared, nextfile is not a standard awk statement. Try just taking it out. CaKiwi
 
Sweet! Perfect CaKiwi! Worked awesome!
 
Great! It will work fine as long as you have only one RXOTG record in each file. Send my beers through using Beer Pal. CaKiwi
 
Sorry Beaster I was occupied through the day.
Cakiwi is a better coder than I am anyway so you got
the best of the deal. ;)
 
No prob Marsd, you and CaKiwi are both very good and I always appreciate help from either of you two!!!!
 
Back from your other thread, what needs to be changed? All the TG_NUM have been changed to 121 as in your example output. Did you mean that only the RXOTG-TG_NUM should be chabged to RXOTG-121? CaKiwi
 
Well you both will be pleased to know I was the one who screwed it all up! Go figure.....

It has been running correctly, but I had been complaining that the number 121 was showing up in all three files. Well that was what it was supposed to do...If I had looked at my input file master_sorted I would have seen I set it up to look for $3 from the previous post, which all had 121 for $3. I have learned my lesson again!

Thanks for all the time and effort, both of you have been an enormous help!

Beaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top