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 3632114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:29:03+00:00 2026-05-19T00:29:03+00:00

I want to store the output of text file into a variable, so I

  • 0

I want to store the output of text file into a variable, so I can pass the whole file as parameter.

I am using Windows 2003 Server.

The text files have multiple lines like:

10.20.210.100 fish
10.20.210.101 rock

I was using:

Set /P var=<file.txt

It reads only the first line of the file.

I tried with FOR loop also but it assigned only the last line to the variable.

  • 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-19T00:29:04+00:00Added an answer on May 19, 2026 at 12:29 am

    There is no simple way to get the complete content of a file into one variable.
    A variable has a limit of ~8100 length.
    And it is complicated to get CR/LF into a variable

    But with a FOR-loop you can get each single line.

    Try a look at batch script read line by line

    EDIT:
    To get each line in a single variable you can use this

    @echo off
    SETLOCAL EnableDelayedExpansion
    set n=0
    for /f "delims=" %%a IN (example.txt) do (
      set /a n+=1
      set "line[!n!]=%%a"
      echo line[!n!] is '%%a'
    )
    set line
    

    or to get all in only one variable (without CR/LF)

    @echo off
    SETLOCAL EnableDelayedExpansion
    set "line="
    for /f "delims=" %%a IN (example.txt) do (
      set "line=!line! %%a"
    )
    echo !line!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which i want to store all the outputs into one
I want to store a user setting(language). so i can get the corresponding resources
I want to store a .NET object into Azure Blob Storage. Currently I serialize
I am trying to log the output of tests to a text file. I
I have a text file as an output of a c++ program. Its actually
Using C++'s <fstream> , it's pretty easy to copy a text file: #include <fstream>
I am a python newbie. I want to read a text file which reads
Hi programmers, I want read line by line a Unicode (UTF-8) text file created
I want make a game of life clone using text files to specify my
I'm trying to create my own file format. I want to store image file

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.