问题
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 :-(
回答1:
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 !!!!!
回答2:
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
)
回答3:
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.
来源:https://stackoverflow.com/questions/537404/assign-win-xp-commandline-output-to-variable