ASSIGN outputs XP command line output to a variable

I would like to translate the 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 is translated; The problem is to define a variable that contains shell output in windows: - (

+5
source share
3 answers

ok fixed the problem

 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 does what I wanted to do.

Thank you !!!!!

+4
source

If you need to recurs through the output of a command, you can use for /f . Sort of:

 for /f "usebackq" %%L in (`awk '/GPSID/ {print $3}' gora.RTK`) do ( awk 'BEGIN {printf "Numer seryjny : " %%L,$1}' >> out.txt ) 
+1
source

What about...

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

NOTE: use% a instead of %% a when trying on the command line, save it as %% a if used 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 in which the output will be saved.

0
source

Source: https://habr.com/ru/post/973426/


All Articles