| Author |
inserting text at top that depends on info at end of file....
|
|
|
| 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.
| |
|
|
|
|
|
|