Batch Read Line From File Into Variable

Bash Read Line From File

Reading Lines from a Text File with. Line to a variable. For example my batch file is. How to read file contents into a variable in a batch. Of the version.txt file into a variable in the batch. With only a single line in the file.

I've made a good deal of headway by searching this site and learning the ridiculous language that is Windows batch scripting, but I'm now at a point where I'm stuck. I have always had problems with comma separated values in a for loop. Here's what I did to make your code work. However, and rather puzzlingly, the first two lines of the output file are the last two lines of the input file -- reversed!

See More On Stackoverflow

The last line of the input file is blank, and the line before it contains data. In the output file, I'm getting the blank line as the first line, then the second-last line. Then the rest of the file starts from line 1 of the input file and continues in order so that the last line of the output file is the third-last line of the input file! – Jul 3 '13 at 17:11 •. How To Mkv File From Youtube.

I have a log file which I need to read in, line by line and pipe the line to a next loop. Firstly I grep the logfile for the 'main' word (like 'error') in a separate file - to keep it small. Now I need to take the seperate file and read it in line by line - each line needs to go to another loop (in these loop I grep the logs and divide it in blocks) but I stuck here. The log looks like xx.xx.xx.xx - - '200 - 'something_else' with a for /f loop I just get the IP instead of the complete line. Jakers Las Aventuras De Piggley Winks. How can I pipe/write/buffer the whole line? (doesn't matter what is written per line). Try this: @echo off for /f 'tokens=*'%%a in (input.txt) do ( echo line=%%a ) pause because of the tokens=* everything is captured into%a edit: to reply to your comment, you would have to do that this way: @echo off for /f 'tokens=*'%%a in (input.txt) do call:processline%%a pause goto:eof:processline echo line=%* goto:eof:eof Because of the spaces, you can't use%1, because that would only contain the part until the first space.

And because the line contains quotes, you can also not use:processline '%%a' in combination with%~1. So you need to use%* which gets%1%2%3., so the whole line. The 'call' solution has some problems. It fails with many different contents, as the parameters of a CALL are parsed twice by the parser. These lines will produce more or less strange problems one two%222 three & 333 four=444 five'555'555' six'&666 seven!777^!