replace string AFTER "size","initial", "next" 
Author Message
 replace string AFTER "size","initial", "next"

Hi,

I'm new to awk and am stumped on how to do this.  I'm appreciate any help.

I have a database export file.  In this export file are some size
parameters I would like to change.  There are hundreds of them and they
currently have different values.  The values I would like to change come
after the words:

SIZE, INITIAL and NEXT.  There is a space after these three strings
and a space after the value.   I would like the value after SIZE to be
20000 and after INITIAL and NEXT to be 1000.

The text would look something like this:

CREATE TABLESPACE ..... SIZE 2432323 ( INITIAL 34343 NEXT
454323 )

In some cases, SIZE would not precede INITIAL and NEXT.

Thanks in advance for any help,



Tue, 26 Jun 2001 03:00:00 GMT  
 replace string AFTER "size","initial", "next"

Quote:

>Hi,

>I'm new to awk and am stumped on how to do this.  I'm appreciate any help.

>I have a database export file.  In this export file are some size
>parameters I would like to change.  There are hundreds of them and they
>currently have different values.  The values I would like to change come
>after the words:

>SIZE, INITIAL and NEXT.  There is a space after these three strings
>and a space after the value.   I would like the value after SIZE to be
>20000 and after INITIAL and NEXT to be 1000.

>The text would look something like this:

>CREATE TABLESPACE ..... SIZE 2432323 ( INITIAL 34343 NEXT
>454323 )

>In some cases, SIZE would not precede INITIAL and NEXT.

>Thanks in advance for any help,

I will assume that the records are all on one line, and that the
text is not split over two lines, so a sample record would look like:

CREATE TABLESPACE ..... SIZE 2432323 ( INITIAL 34343 NEXT 454323 )

the sub or gsub function is what you want to use

gawk '{gsub(/SIZE [0-9][0-9]* /,"SIZE 20000 ");
       gsub(/INITIAL [0-9][0-9]* /,"INITIAL 1000 ")
       gsub(/NEXT [0-9][0-9]* /,"NEXT 1000 ");
       print}' infile > outfile

should do the job.

It produces this output on the sample input I used:

CREATE TABLESPACE ..... SIZE 20000 ( INITIAL 1000 NEXT 1000 )

You could also do this with sed, but this is an awk newsgroup.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Tue, 26 Jun 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

2. BEGIN{want[]={"s1o", "s2o", "s2q", "s3q"}

3. Parsing ""D""?

4. "Fifth", "Forth", zai nar?

5. Ruby "finalize", "__del__"

6. beginners "let"/"random" question

7. ANNOUNCE: new "plus"- and "dash"-patches available for Tcl7.5a2/Tk4.1a2

8. Looking for "stdin", "stdout"

9. Hi, this code: text0 = "One $BLAH Three" text1 = "One @BLAH Three" text0.sub!("$BLAH", "Two") text1.sub!("@BLAH", "Two") print text0,"\n" print text1,"\n" produces thiHi, this code: text0 = "One $BLAH Three" text1 = "One @BLAH Three" text0.sub!("$BLAH", "T

10. Match "ab" in "abc", but not in "abd"

11. Lack of "D Tests", "E Tests", and "L Tests" for Generics

12. "?:", "a and b or c" or "iif"

 

 
Powered by phpBB® Forum Software