ASSIGN win XP commandline output to variable

倖福魔咒の 提交于 2020-01-01 11:49:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!