1.

Solve : Open and Read from file with MS-DOS?

Answer»

I was wondering if anyone knows how to open an existing file and read line by line using MS-DOS? Also does anyone know how to parse out an existing value and replace it with a new value within a file using MS-DOS?

Thanks
ChenDepends on the file and what exactly you want to accomplish here...
More details.there are couple things I want to do....

1) I am tyring to open a file that contains names seperated by line feed. I would have a variable that will take in one name at a time and do some process.

2) Second THING I want to do is I have an .ini file that I want to modify. I will need to search for a string, deleted the existing string value and replace it with new string values.

Let me know if you need more info.download GNU awk for windows here (gawk).


QUOTE from: chsu05 on January 30, 2008, 01:08:19 PM

there are couple things I want to do....

1) I am tyring to open a file that contains names seperated by line feed. I would have a variable that will take in one name at a time and do some process.
Depends on what you want to do,
Code: [Select]gawk "{
#do processing line by line,
}
" file.txt

Quote
2) Second thing I want to do is I have an .ini file that I want to modify. I will need to search for a string, deleted the existing string value and replace it with new string values.

Let me know if you need more info.
Using gawk again code snippet, again depending on what you want to do
Code: [Select]gawk " {
#read line by line, search for pattern then substitute
}" myfile.ini


Let me rephrase what I want....

I want to open a file that contains a list of values.
Ex values in File:
ABC
DEF
GHI
JKL

Then read in each value one at a time.
Ex.
set %value1%=ABC
set %VALUE2%=DEF
set %value3%=GHI
set %value4%=JKL

Can MS-DOS automate this?

Another way to understand what I want is using DOS to open a file and read in line by line.

ThanksMS-DOS, really? What version?

Code: [Select]@echo off
set idx=0
for /f %%x in (input.txt) do (
call set /a idx=%%idx%%+1
call set value%%idx%%=%%x
)

You can try this. I don't remember when the for /f switch was introduced. After running, use the set command at the prompt to see your variables.

Good luck. well I am not sure what version of MS-DOS I am using since I have limited access. I know what version of EDITOR in MS-DOS (2.0).

As for the for loop... I tried it and it works great. So now instead of 10 pages of code I only have 2 pages of code since I won't have to copy and paste same code over and over again.

Thx!


Discussion

No Comment Found