Run awk from within sed script? 
Author Message
 Run awk from within sed script?

Is it possible to run awk from within a sed script?  I need to do a
replacement of some numbers inside of one file.  However, I have to get two
new numbers from another file and then do an 'add' to put them back into the
first file.

For example.

File1
====
xll 100
yll 100

File2
====
xmin 200
ymin 200
xmax 300
ymax 300

I need to replace the values in File2 for xmin, ymin, xmax, ymax.  xmin and
ymin come from File1 xll and yll respectively.  Then, I need to take those
numbers and add 100 to them to get xmax and ymax.

I thought of making a template where I could replace the numbers in File2 to
something more specific that would be easier to search from as there are
other occurrences of xmin and such.  My thought was to make File2 look like
this.

File2
====
xmin XMIN
ymin YMIN
xmax XMAX
ymax YMAX

Then, I could run the sed script and search for XMIN,etc specifically and do
the replace.  But, how do I grab the numbers from File1 and put them into
File2?

Bruce.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 04 Jan 2003 03:00:00 GMT  
 Run awk from within sed script?

Quote:

>Is it possible to run awk from within a sed script?

No.  Well, not that I know of.  

Quote:
>I need to do a
>replacement of some numbers inside of one file.  However, I have to get two
>new numbers from another file and then do an 'add' to put them back into the
>first file.

Awk can do this, why bother using sed too?

Quote:
>For example.

>File1
>====
>xll 100
>yll 100

>File2
>====
>xmin 200
>ymin 200
>xmax 300
>ymax 300

>I need to replace the values in File2 for xmin, ymin, xmax, ymax.  xmin and
>ymin come from File1 xll and yll respectively.      Then, I need to take those
>numbers and add 100 to them to get xmax and ymax.

>I thought of making a template where I could replace the numbers in File2 to
>something more specific that would be easier to search from as there are
>other occurrences of xmin and such.  My thought was to make File2 look like
>this.

>File2
>====
>xmin XMIN
>ymin YMIN
>xmax XMAX
>ymax YMAX

>Then, I could run the sed script and search for XMIN,etc specifically and do
>the replace.  But, how do I grab the numbers from File1 and put them into
>File2?

Do the whole job with awk.  Here's one way:

awk 'FILENAME=="File1" && /^xll /  {xmin=$2; xmax=xmin+100; next}
     FILENAME=="File1" && /^yll /  {ymin=$2; ymax=ymin+100; next}
     FILENAME=="File2" && /^xmin / {$2=xmin; print; next}
     FILENAME=="File2" && /^ymin / {$2=ymin; print; next}
     FILENAME=="File2" && /^xmax / {$2=xmax; print; next}
     FILENAME=="File2" && /^ymax / {$2=ymax; print; next}
     FILENAME=="File2"             {print}' File1 File2 > New_File2

Chuck Demas
Needham, Mass.

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

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



Sat, 04 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Running Awk scripts from within VB

2. Access to Script Name Within Awk Script

3. Running a TK script using wish80.exe within a tcl script

4. Running scripts within scripts

5. Running sed/awk on SQL results

6. sed/awk script to format a file??

7. trying to call awk from within a shell script

8. shell commands within awk script

9. using Oracle within an awk script

10. Simple awk command within a perl script

11. awk within ksh script

12. Shell variable within an awk script

 

 
Powered by phpBB® Forum Software