Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:28:18+00:00 2026-06-12T07:28:18+00:00

I am trying to use the cut equivalent for DOS but it is not

  • 0

I am trying to use the cut equivalent for DOS but it is not working in my for loop.

Content of weekly_date.txt

18092012                                                                        
19092012                                                                        
20092012                                                                        
21092012                                                                        
22092012                                                                        
23092012                                                                        
24092012                                                                        

I am running a batch script & facing a variable value substitution problem in below part:

for /f %%I in (weekly_date.txt) do ( 

echo %%I
set yy=%%I:~4,4%
set mm=%%I:~2,2%
set dd=%%I:~0,2%

echo %yy%

SET bp=/xx/yy/%mm%/%dd%
SET br=/aa/bb/%mm%/%dd%
SET TP=F:\xx\%yy%\%mm%\%dd%\yy

echo %bp%
echo %br%
echo %TP% )

done

Then in

SET bp=/xx/yy/%/%mm%/%dd%
SET br=/aa/bb/%/%mm%/%dd%
SET TP=F:\xx\%yy%\%mm%\%dd%\ff 

It’s getting substituted in below manner when running batch script

SET bp=/xx/yy/%i:~2,2/%i:~0,2  
SET br=/aa/bb/%i:~2,2/%i:~0,2  
SET TP=F:\xx\%i:~4,4\%i:~2,2\%i:~0,2\ff   

Actually the output must be

/xx/yy/09/18
/aa/bb/09/18
F:\xx\2012\09\18\ff


/xx/yy/09/19
/aa/bb/09/19
F:\xx\2012\09\19\ff

....
...

/xx/yy/09/24
/aa/bb/09/24
F:\xx\2012\09\24\ff

Can any one point out where I am going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:28:20+00:00Added an answer on June 12, 2026 at 7:28 am

    For your code I would make two main changes: 1)set the input of the for loop to another variable (called var) for manipulation 2)Enable delayed expansion, which allows the variable to be manipulated with each for loop iteration. Let me know if any additional changes need to be made to my code =]

    My code is as follows:

    @echo off
    setLocal EnableDelayedExpansion
    
    for /f %%I in (weekly_date.txt) do ( 
    set var=%%I
    set yy=!var:~4,4!
    set mm=!var:~2,2!
    set dd=!var:~0,2!
    
    set bp=/xx/yy/!mm!/!dd!
    set br=/aa/bb/!mm!/!dd!
    set TP=F:\xx\!yy!\!mm!\!dd!\ff
    
    echo !bp! !br! !TP!
    )
    
    endlocal
    

    Using the same weekly_dates.txt input you provided, the output of this code is:

    /xx/yy/09/18 /aa/bb/09/18 F:\xx\2012\09\18\ff 
    /xx/yy/09/19 /aa/bb/09/19 F:\xx\2012\09\19\ff 
    /xx/yy/09/20 /aa/bb/09/20 F:\xx\2012\09\20\ff 
    /xx/yy/09/21 /aa/bb/09/21 F:\xx\2012\09\21\ff 
    /xx/yy/09/22 /aa/bb/09/22 F:\xx\2012\09\22\ff 
    /xx/yy/09/23 /aa/bb/09/23 F:\xx\2012\09\23\ff 
    /xx/yy/09/24 /aa/bb/09/24 F:\xx\2012\09\24\ff 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use Unix cut to remove the first two fields per line.
I am trying to cut over an existing WebForms app to use Routing, and
I am working on a modularized Flex application, and I am trying to cut-down
Ok so I know long hand ajax but trying to use the jQuery short
I'm trying to use delegates to cut down on my code in this project.
I'm trying to use tinymce editor with facebox modal window. But tinymce doesn't load
I have been trying to use JScrollPane with my applet, but it doesn't work.
I am trying to use jQuery's .data() tool in a jQuery plugin but I'm
I am working in VB.Net and trying to use Regex.Replace to format a string
I'm trying to use the ViewPageIndicator library in my class, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.