views:

1878

answers:

3

i would like to translate a following script from linux shell to Windows XP shell

GPSID=$(awk '/GPSID/ {print $3}' gora.RTK ) 
awk -v variable=${GPSID} 'BEGIN {printf "Numer seryjny : " variable,$1}' >>out.txt

The second line has been translated; the problem is with defining a variable that contains shell output in windows :-(

A: 

How about ...

for /f "tokens=*" %%a in ('echo Hello World') do set var=%%a

NOTE: use %a instead of %%a when trying on the command line else keep it as %%a if using in a batch file.

Where 'echo Hello World' is the command whose output you want to capture and "var" is the name of the variable where the output will be stored.

SDX2000
That is as close as you will be able to come, but the OP should be aware that multiline strings cannot be stored in a DOS var.
EBGreen
+1  A: 

If you need to recurse through the output of the command, you can use for /f. Something like:

for /f "usebackq" %%L in (`awk '/GPSID/ {print $3}' gora.RTK`) do (
    awk 'BEGIN {printf "Numer seryjny : " %%L,$1}' >> out.txt
)
Patrick Cuff
Sorry, I'm not awk proficient, but hopefully you get the idea.
Patrick Cuff
+2  A: 

ok problem fixed

for /f "tokens=*" %%a in ('awk "/GPSID/ {print $3}" gora.RTK ') do set var=%%a
awk "BEGIN {printf \"GPSID : \" }" >out.txt
echo %var% >>out.txt

This code basicly does what I wanted to do.

You are great Thanks !!!!!