Ricardo Bohner
Ricardo Bohner

Reputation: 365

How to align text in colums in batch

I would like to get user input and align it in colums using a batch file.

What I would like to archive is put a username in the beginning of the file and let's say the age on the 20th character of the file:

enter image description here

But I don't know how to put an input in on a exact position inside a variable or a text file:

@echo off
:start
cls
echo.
set /p "name=Please insert your name: "
set /p "age=Please insert your age: "

set line=%name%
set %line:~21,3%=%age%
echo %line%>>%userprofile%\desktop\names.txt
goto :start

Upvotes: 0

Views: 1026

Answers (1)

Compo
Compo

Reputation: 38604

The technique below pads the supplied name with twenty spaces, then echoes the first nineteen characters.

Quick example:

@Echo Off

:start
    ClS
    Echo(
    Set /P "name=Please insert your name: "
    Set /P "age=Please insert your age: "

    Set "line=%name%                    "
    >>"%userprofile%\desktop\names.txt" Echo(%line:~,19%%age%
    GoTo :start

Upvotes: 3

Related Questions