I am trying to open a text file, read it line by line, use each line in script commands. I am having trouble getting it to work.
The text file being opened and read looks as follows:
abc:123-def
ghi:456-jkl
mno:789-pqr
I am opening the file and looping thru with the following code:
set "spath=C:\myscript\"
FOR /F %%a in (test.txt) do (echo %%a
findstr ":" %%a | cut -f1 -d ":" > val1.txt
findstr ":" %%a | cut -f1 -d "-" > val2.txt
findstr ":" %%a | cut -f1 -d "-" > val3.txt
finalval=%val1% + %val2%
echo %finalval%
finalval > val3.txt
}
I have tried multiple ways but can't seem to get this to work. The val1.txt and val2.txt gets created but I can never get finalval to work. Either only the last line in test.txt is the only one used or nothing. I know val1 and val2 changes each time thru. The methodlogy is that the test.txt acts like an array almost, where each line is parsed, used in the operation, then the finalval is saved to text file named value currently stored in val3.
Loop Thru File Use Line Value in Operation
Moderator: DosItHelp
Re: Loop Thru File Use Line Value in Operation
Many thanks, after the do statement, is it possible to multiple commands on the same line, or do you have to use ( )?
Re: Loop Thru File Use Line Value in Operation
btpoole wrote:Many thanks, after the do statement, is it possible to multiple commands on the same line, or do you have to use ( )?
Whatever trips your trigger. I prefer readability. I usually will shy away from helping people with their batches files if they are not formatted for readability.