Search found 44 matches
- 30 Apr 2019 14:26
- Forum: DOS Batch Forum
- Topic: how to read line in text file and return it by function
- Replies: 5
- Views: 4344
how to read line in text file and return it by function
In my situation, command string in function used to make return value from function is necessary. :test2 setlocal EnableDelayedExpansion set "_ret=" for /f "delims=" %%i in (temp.txt) do ( setlocal DisableDelayedExpansion rem echo %%i set "_ret=set %~1=%%i" endlocal ) ( endlocal %_ret% ) goto :eof s...
- 30 Apr 2019 14:20
- Forum: DOS Batch Forum
- Topic: In for loop, how to pass variable from one setlocal to another
- Replies: 4
- Views: 3889
- 25 Apr 2019 16:25
- Forum: DOS Batch Forum
- Topic: In for loop, how to pass variable from one setlocal to another
- Replies: 4
- Views: 3889
Re: In for loop, how to pass variable from one setlocal to another
Will it cause: “reach max recurse of setlocal” error?
- 25 Apr 2019 15:33
- Forum: DOS Batch Forum
- Topic: Read line from two text files and make output
- Replies: 4
- Views: 3466
- 25 Apr 2019 15:27
- Forum: DOS Batch Forum
- Topic: In for loop, how to pass variable from one setlocal to another
- Replies: 4
- Views: 3889
In for loop, how to pass variable from one setlocal to another
:test1 setlocal EnableDelayedExpansion set "source_bat_file=txt1.txt" for /f "delims=" %%i in (%source_bat_file%) do ( rem echo %%i setlocal DisableDelayedExpansion set "line1=%%i" echo 1: %line1% endlocal&set line1=%line1% setlocal EnableDelayedExpansion echo 2: !line1! endlocal pause ) endlocal g...
- 25 Apr 2019 12:47
- Forum: DOS Batch Forum
- Topic: Read line from two text files and make output
- Replies: 4
- Views: 3466
Re: Read line from two text files and make output
Hi Steffen, I notice that you use command “findstr /n” to list lines in second input file with line number at start of each line. And when you do comparing two lines, you remove “:” and any characters before this “:” from each line in second input file. A moment ago, I get why you use “/n” to list l...
- 22 Apr 2019 05:49
- Forum: DOS Batch Forum
- Topic: Read line from two text files and make output
- Replies: 4
- Views: 3466
Read line from two text files and make output
Hi, What I want is described in following pseudo code: file1=openfile in1.txt file2=openfile in2.txt file_out=openfile out.txt while not file1.EOF and not file2.EOF { // in each loop, read next line from file1 and file2 line_in_file1=file1.ReadLine line_in_file2=file2.ReadLine // two lines are not s...
- 22 Apr 2019 05:24
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Re: Some content of text file lost when printing to screen
txt1.txt abc ##xyz def ##foo bar *.bat @echo off &setlocal set "in_file=txt1.txt" set "out_file=txt2.txt" setlocal EnableDelayedExpansion set "n=0" <"!in_file!" >"!out_file!" ( for /f %%i in ('type "!in_file!"^|find /c /v ""') do for /l %%j in (1 1 %%i) do ( set "line=" &set /p "line=" if not defin...
- 21 Apr 2019 05:29
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Re: Some content of text file lost when printing to screen
Hi Steffen,
The text file I deal with is my source code, it is not too long in each line. Every line in my code is not get close to 1021 characters.
Thanks
- 20 Apr 2019 23:54
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Re: Some content of text file lost when printing to screen
Hi Steffen,aGerman wrote: ↑20 Apr 2019 12:03Give this a go:SteffenCode: Select all
>>"txt2.txt" findstr /vb "##" "txt1.txt"
With your code, how can I get count of lines starting with ##
And I want to do some operations on the line not starting with ##, what should I do?
Thanks
- 20 Apr 2019 11:06
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Re: Some content of text file lost when printing to screen
I am trying to read each line from a text file, and if the line does not begin with ##, append this line to another text file.
thanks
thanks
- 20 Apr 2019 00:27
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Re: Some content of text file lost when printing to screen
If I echo %%i to a text file, is there any way to preserve !var2! in the text file?
Thanks
Thanks
- 19 Apr 2019 17:11
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Re: Some content of text file lost when printing to screen
Is there any other way? In my function the delayed expansion is necessary.
- 19 Apr 2019 13:41
- Forum: DOS Batch Forum
- Topic: Some content of text file lost when printing to screen
- Replies: 17
- Views: 20306
Some content of text file lost when printing to screen
:test1 setlocal EnableDelayedExpansion for /f "delims=" %%i in (txt1.txt) do ( echo %%i ) endlocal goto :eof content of text file txt1.txt: 111 222 set var1=!var2! when I run the code, I found that when printing third line in txt1.txt, !var2! is lost. How to preserve !var2! in screen? Thanks
- 15 Apr 2019 10:56
- Forum: DOS Batch Forum
- Topic: how to preserve leading spaces in parameter during function call
- Replies: 4
- Views: 4079
Re: how to preserve leading spaces in parameter during function call
Hi jeb,
Your code works fine.
thanks a lot
Your code works fine.
thanks a lot