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
3
  • 1
    Are you using two user accounts (similar question)? why?? Anyway, show sample content of the URL in your question! To add 1, use set/A "return=%%i+1"... Commented Aug 14, 2018 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 Commented Aug 14, 2018 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... Commented Aug 14, 2018 at 14:38

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.