Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

store retunning value from awk script to system variable

100 views
Skip to first unread message

happytoday

unread,
Aug 19, 2012, 8:51:34 PM8/19/12
to
How can under batch file to store value for returning value from awk
program ?

Ed Morton

unread,
Aug 20, 2012, 7:54:55 AM8/20/12
to
On 8/19/2012 7:51 PM, happytoday wrote:
> How can under batch file to store value for returning value from awk
> program ?
>

This has nothing to do with the awk language, it's a question for your OS so ask
it in an appropriate NG.

Ed.

Loki Harfagr

unread,
Aug 20, 2012, 1:11:28 PM8/20/12
to
Sun, 19 Aug 2012 17:51:34 -0700, happytoday did cat :

> How can under batch file to store value for returning value from awk
> program ?

for a direct answer to your direct question use Ed.'s answer
for an indirect answer to your hidden probable question I'd say
first use a file then use source on it

a little PoC goes a long way cause it's hot:

your given env var:
-------------
$ export _BARF=888
-------------

the PoC script:
-------------
$ cat bhappy.sh
#!/bin/bash

### call thrice an awk script that might have a try at
### incrementing an environment variable
### this is the given env variable to play with
echo "Before anything goes: $_BARF"
_BARF=999
export _BARF
echo "Right after first fighting: $_BARF"
###
### this is the simple mind awk to do just what to do
###
cat<<EOF>bhappy.awk
BEGIN{
x=ENVIRON["_BARF"]
x+=101
ENVIRON["_BARF"]=x
printf("\n\tin awk, x=%s, envB=%s.\n",x,ENVIRON["_BARF"])
}
EOF
###
cat<<EOT>bhappy2.awk
BEGIN{
x=ENVIRON["_BARF"]
x+=101
printf("export _BARF=%s\n",x) > _fout_
}
EOT
###
awk -f bhappy.awk
### wont work as is
export _BARF

awk -v _fout_="/tmp/_barfmeup" -f bhappy2.awk
. /tmp/_barfmeup
### might and magic
awk -v _fout_="/tmp/_barfmeup" -f bhappy2.awk
. /tmp/_barfmeup

###
###
###
echo "There was a showdown this place: $_BARF"
-------------

just counting cards:
-------------
./bhappy.sh
Before anything goes: 888
Right after first fighting: 999

in awk, x=1100, envB=1100.
There was a showdown this place: 1201
-------------

Serious_Developer

unread,
Sep 12, 2012, 6:01:29 PM9/12/12
to
On Aug 20, 7:11 pm, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
wrote:
I must recall that thread again to notify that command is not working
from sindei a batch file :

:loop
set source=%dir%\%codeloop%
if /I %codeloop% GTR %MAX% goto :End

echo %source%
pause ""
pushd %source%
dir /b "%source%\TMP*.RPT" > %source%\dir.txt
@for /F "tokens=*" %%* in (%source%\dir.txt) do (
@%binaries%\gawk -f %scripts%\alexbank_distribute_branches.awk %source%
\%%* 2> %scripts%\alexbank_distribute_branches.fil
echo from inside batch %codeinsidebat%
pause ""
)


My alexbank_distribute_branches.awk does not produce the value to
codeinsidebat variable using that statement :

ENVIRON["codeinsidebat"]=codeawk

Loki Harfagr

unread,
Sep 13, 2012, 2:29:36 AM9/13/12
to
Wed, 12 Sep 2012 15:01:29 -0700, Serious_Developer did cat :

> On Aug 20, 7:11 pm, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
> wrote:
>> Sun, 19 Aug 2012 17:51:34 -0700, happytoday did cat :
>>
>> > How can under batch file to store value for returning value from awk
>> > program ?
>>
>> for a direct answer to your direct question use Ed.'s answer
>> for an indirect answer to your hidden probable question I'd say
>> first use a file then use source on it
>>
>> a little PoC goes a long way cause it's hot:
>>
>> your given env var:
>> -------------
>> $ export _BARF=888
>> -------------
>>
>> the PoC script:
>> -------------
>> $ cat bhappy.sh
...
>> -------------
>>
>> just counting cards:
>> -------------
>>  ./bhappy.sh
>> Before anything goes: 888
>> Right after first fighting: 999
>>
>>         in awk, x=1100, envB=1100.
>> There was a showdown this place: 1201
>> -------------
>
> I must recall that thread again to notify that command is not working
> from sindei a batch file :

OK, might be, no idea what this 'batch' shell is nor what "OS"
(or pushed-up WM) you use it on, and that's a secret you seem
eager to keep, more than 3 weeks without a wink of an eye...
Hence now "@goto Ed-answer" ;-)

Lew Pitcher

unread,
Sep 13, 2012, 11:22:03 AM9/13/12
to
On Wednesday 12 September 2012 18:01, in comp.lang.awk,
ehabaz...@gmail.com wrote:

> On Aug 20, 7:11 pm, Loki Harfagr <l...@thedarkdesign.free.fr.INVALID>
> wrote:
>> Sun, 19 Aug 2012 17:51:34 -0700, happytoday did cat :
>>
>> > How can under batch file to store value for returning value from awk
>> > program ?
[snip]
> I must recall that thread again to notify that command is not working
> from sindei a batch file :
>
> :loop
> set source=%dir%\%codeloop%
> if /I %codeloop% GTR %MAX% goto :End
>
> echo %source%
> pause ""
> pushd %source%
> dir /b "%source%\TMP*.RPT" > %source%\dir.txt
> @for /F "tokens=*" %%* in (%source%\dir.txt) do (
> @%binaries%\gawk -f %scripts%\alexbank_distribute_branches.awk %source%
> \%%* 2> %scripts%\alexbank_distribute_branches.fil
> echo from inside batch %codeinsidebat%
> pause ""
> )
>
>
> My alexbank_distribute_branches.awk does not produce the value to
> codeinsidebat variable using that statement :
>
> ENVIRON["codeinsidebat"]=codeawk

Your question relates to how your batch language works; specifically, what
batch language syntax is necessary to transfer the output from a batch
script into an environment variable.

This is a question for a Microsoft Windows scripting newsgroup, not
comp.lang.awk. You might find the proper forum in the microsoft.*
newsgroups.

Sorry, but I'm not a CMD.EXE batch scripting expert.
--
Lew Pitcher
"In Skills, We Trust"

Loki Harfagr

unread,
Sep 13, 2012, 1:17:12 PM9/13/12
to
Thu, 13 Sep 2012 11:22:03 -0400, Lew Pitcher did cat :
nice to see we're all on the page, Lew :-)

>
> This is a question for a Microsoft Windows scripting newsgroup, not
> comp.lang.awk. You might find the proper forum in the microsoft.*
> newsgroups.
>
> Sorry, but I'm not a CMD.EXE batch scripting expert.

Now that we both wrote the same answer while using slightly
different "proxemies" it'd be interesting to know (probably in
January or so) which one gave the OP the final incentive hint ;D)
0 new messages