Search found 44 matches

by sincos2007
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: 621

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...
by sincos2007
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: 539

Re: In for loop, how to pass variable from one setlocal to another

Will it cause: “reach max recurse of setlocal” error?
by sincos2007
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: 539

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...
by sincos2007
25 Apr 2019 12:47
Forum: DOS Batch Forum
Topic: Read line from two text files and make output
Replies: 4
Views: 541

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...
by sincos2007
22 Apr 2019 05:49
Forum: DOS Batch Forum
Topic: Read line from two text files and make output
Replies: 4
Views: 541

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...
by sincos2007
22 Apr 2019 05:24
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

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...
by sincos2007
21 Apr 2019 05:29
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

Re: Some content of text file lost when printing to screen

aGerman wrote:
21 Apr 2019 04:31
What's the maximum length of a line in your txt1.txt. Is there any risk to get close to 1021 characters?

Steffen
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
by sincos2007
20 Apr 2019 23:54
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

Re: Some content of text file lost when printing to screen

aGerman wrote:
20 Apr 2019 12:03
Give this a go:

Code: Select all

>>"txt2.txt" findstr /vb "##" "txt1.txt"
Steffen
Hi Steffen,

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
by sincos2007
20 Apr 2019 11:06
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

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
by sincos2007
20 Apr 2019 00:27
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

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
by sincos2007
19 Apr 2019 17:11
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

Re: Some content of text file lost when printing to screen

Is there any other way? In my function the delayed expansion is necessary.
by sincos2007
19 Apr 2019 13:41
Forum: DOS Batch Forum
Topic: Some content of text file lost when printing to screen
Replies: 17
Views: 3296

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