2

I want to get last line of this link (https://pastebin.com/raw/s5BxuEEw) and +1 it and save as integer.

For example if the last line is 5 , put 6 in variable.

I can get content with this code but I dont know how to filter last line:

@echo off
for /f "tokens=*" %%i in ('powershell /command "(Invoke-WebRequest -Uri 'https://pastebin.com/raw/s5BxuEEw').Content"') do set return=%%i
echo "%return%"
pause
Aria Fathi
  • 23
  • 3
  • 1
    Are you using [two user accounts](https://stackoverflow.com/q/51838933) (similar question)? why?? Anyway, show sample content of the URL in your question! To add 1, use [`set`](http://ss64.com/nt/set.html)`/A "return=%%i+1"`... – aschipfl Aug 14 '18 at 11:58
  • I dont know why it wont allow me to send another Q, anyways, I want to get the last number and +1 it, for example if the last line is 5 , +1 it and save as a variable. As you said, I now know how to add +1, I just dont know how to get the last line only @aschipfl – Aria Fathi Aug 14 '18 at 12:06
  • `for /F` iterates over all lines, but the variable `return` becomes overwritten in every iteration, therefore the last value remains after the loop... – aschipfl Aug 14 '18 at 14:38

1 Answers1

2

To select only the last line from url content use index [-1]
(but the for /f would nevertheless iterate ALL lines and only the last persists)

To add / increment a number use set /A

@echo off
set "URI=https://pastebin.com/raw/s5BxuEEw"
for /f "tokens=*" %%i in ('
  powershell -NoP -C "(Invoke-WebRequest -Uri '%URI%').Content[-1]"
') do set /A "return=%%i+1"
echo "%return%"
pause

Sample output is

"6"