Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

Help with For block commands--command/batch file parsing


  • Please log in to reply
No replies to this topic

#1 ray5450

ray5450

  •  Avatar image
  • Members
  • 734 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:03:46 PM

Posted 18 May 2021 - 08:26 PM

Here is my working test:

 

set line=abc1234
set line2=%line:~0,3%
echo %line2%
pause

 

The expected output is:  abc, and it is.

 

 

Here is the goal:

 

FOR /F "tokens=*" %%i IN (d:\rt.txt) DO (
  set line=%%i
  set line2=%line:~0,3%
  echo %line2%
)
pause

 

When %%i is ==========================, the expected output is:  ===

 

Instead, the output is:

D:\>(
set line===========================
 set line2=~0,3
 echo
)
ECHO is on.

 

How do I get the expected output?

 

(Eventually, I am going to replace Echo with an If statement, but I want to make sure it is working first.)

 

 

 

 



BC AdBot (Login to Remove)

 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users