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

  • SEARCH
  • Home
  • 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 6107505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:11:44+00:00 2026-05-23T14:11:44+00:00

I would like to create a batch file that converts every line in a

  • 0

I would like to create a batch file that converts every line in a flat file to e specific amount of characters (add spaces at the end of every row).

Example:
I have a text file called "text.txt", and it looks like this:

1
22
333
4444
55555

I would like to run a batch file on it and recieve the following (all lines are 7 characters long):

1......
22.....
333....
4444...
55555..

(I had to replace my spaces with dots to make it visible)

Is this possible, and how?


Update:

Cool, that works perfect.

Is it also possible to convert a blank line (just CRLF) to 7 spaces? When I run the above on a file with empty lines they are deleted.

Thanks!

EDIT: Just to clarify, this is the file:

1
22

333
22

1
4444
55555

And I want to recieve:

1......
22.....
.......
333....
22.....
.......
1......
4444...
55555..

Thanks again!


Update 2:

Andriys answer is getting me a few steps forward. I’ve got a few issues though. If I leave the # sign out, the output will be like this (still periods instead of spaces):

1.......
22......
ECHO is off.
333.....
22......
ECHO is off.
1.......
4444....
55555...

And if a line starts with a space it will be outputted as:

ECHO is off.

Powershell is unfortunately not an option…

This might be a better example,
text.txt:

This is
 the input
file 
     I

 want to convert

Of course now we have to make the records longer, let’s say 20 char.

  • 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-05-23T14:11:45+00:00Added an answer on May 23, 2026 at 2:11 pm

    The FOR loop does omit empty lines. This is by design. To work around that, you could use the following command:

    FIND /N /V "" < sourcefile
    

    It is considered that no line can match "" (empty string), so simply FIND "" < file would produce empty output. But the /V option causes the inversion of the output: instead of the lines that match the search string, FIND is to output those that do not match it. So FIND /V "" < file essentially causes FIND to output all the lines of file. And /N causes every line to be prepended with the line number, like this:

    [number]text
    [number]text
    …
    

    Accordingly, empty lines will look just like this:

    [number]
    [number]
    …
    

    So, now we are able to iterate over all the lines. We only need to remove all the [number] parts, then use @Dave’s idea of appending the spaces and cutting out the first 7 characters. Here’s a full script:

    @ECHO OFF
    FOR /F "delims=" %%L IN ('FIND /N /V "" ^<text.txt') DO CALL :process "%%L"
    GOTO :EOF
    
    :process
    SET "line=%~1"
    SET "line=%line:*]=%       "
    ECHO(%line:~0,7%#
    

    (The # character is only added for visual indication.)

    UPDATE

    Added ( just after ECHO. This solves the ECHO is off issue. Basically, you can use a number of different characters instead of (, like ., or , for instance. But, as shown in this answer, ( seems most reliable.

    UPDATE 2

    Added the "delims=" option to the FOR loop after /F to account for spaces in the text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a batch file that brings up the Windows Turn
I would like to create a batch file to start one IIS application, and
I would like to create a batch file to rename all the files with
I would like to create a batch script, to go through 20,000 links in
I would like create my own collection that has all the attributes of python
I would like create a web service in ASP.Net 2.0 that will supports JSON.
I would like to create a file format for my app like Quake, OO,
I would like to create a stored procedure in MySQL that took a list
I would like to create events for certain resources that are used across various
I am trying to create a batch file that removes tel: from a number

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.