For Programmers: Free Programming Magazines  


Home > Archive > AWK > April 2007 > inserting text at top that depends on info at end of file....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author inserting text at top that depends on info at end of file....
xqtr

2007-03-02, 7:57 am

Hi all!
I've already been through O'Reilly's "sed&awk" but still got no good
idea how to solve the following puzzle.

It's pretty complicated to explain!

Let's say I have a file that looks like this (three lines):

SET ASHCPRT=%val_AEKAPR1%
SET DEFPRT=AEKAPR1
SET DESTSRV=NWFPS01

The value as you see it here "AEKAPR1" is not fixed. This is the value
that should be read. The other two lines are also not fix!

And in the end I'd like to have a file that should look like this with
the following issue: The first and second line should contain the
"value" (xxx.cmd) of the information in the inputfile. In this example
it's AEKAPR1 but this could also be ZWKRPR3 and so on.

new file:

IF EXIST %logonserver%\netlogon\Printer\AEKAPR1.cmd (
CALL %logonserver%\netlogon\Printer\AEKAPR1.cmd
GOTO phase2
)
%logonserver%\postie -h:172.16.0.107 -t:oper@x.com -f:root -s:%workname%
GOTO over
:phase2
SET ASHCPRT=%val_AEKAPR1%
SET DEFPRT=AEKAPR1
SET DESTSRV=AEFPS01
:over

Anyone got an idea?
Ed Morton

2007-03-02, 7:57 am

xqtr wrote:
> Hi all!
> I've already been through O'Reilly's "sed&awk" but still got no good
> idea how to solve the following puzzle.
>
> It's pretty complicated to explain!
>
> Let's say I have a file that looks like this (three lines):
>
> SET ASHCPRT=%val_AEKAPR1%
> SET DEFPRT=AEKAPR1
> SET DESTSRV=NWFPS01
>
> The value as you see it here "AEKAPR1" is not fixed. This is the value
> that should be read. The other two lines are also not fix!
>
> And in the end I'd like to have a file that should look like this with
> the following issue: The first and second line should contain the
> "value" (xxx.cmd) of the information in the inputfile. In this example
> it's AEKAPR1 but this could also be ZWKRPR3 and so on.
>
> new file:
>
> IF EXIST %logonserver%\netlogon\Printer\AEKAPR1.cmd (
> CALL %logonserver%\netlogon\Printer\AEKAPR1.cmd
> GOTO phase2
> )
> %logonserver%\postie -h:172.16.0.107 -t:oper@x.com -f:root -s:%workname%
> GOTO over
> :phase2
> SET ASHCPRT=%val_AEKAPR1%
> SET DEFPRT=AEKAPR1
> SET DESTSRV=AEFPS01
> :over
>
> Anyone got an idea?


It's not clear if you want changes in the existing lines of the file
since in your example the third line changed, but I think this is what
you're looking for:

$ cat file
SET ASHCPRT=%val_AEKAPR1%
SET DEFPRT=AEKAPR1
SET DESTSRV=NWFPS01

$ awk 'NR==1{v=$0; gsub(/(.*_|%)/,"",v); printf "text with %s\n",v}1;
END{print ":over"}' file
text with AEKAPR1
SET ASHCPRT=%val_AEKAPR1%
SET DEFPRT=AEKAPR1
SET DESTSRV=NWFPS01
:over

Just change "text with %s\n" to be whatever you want printed using "v".

Regards,

Ed.
Mooondooogy

2007-03-30, 8:42 am

Catherine Zeta Jone Throatjob!
http://Catherine-Zeta-Jone-Throatjo...hp?movie=148803
Ic3mn

2007-04-17, 5:30 pm

Katie Holmes touching her boobs!
http://Katie-Holmes-touching-her-bo...hp?movie=148803
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com