![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-11 07:58 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » How to read data from a specified line in a config file and assign it to a variable? |
| Printable Version 972 / 6 |
| Floor1 mcubird | Posted 2009-01-19 11:48 |
| 初级用户 Posts 17 Credits 40 | |
|
I wrote a batch file myself, and right now I manually modify the variable parameters.
I want to make a config file and have the batch file assign the parameters to variables. What's the best way to handle it? It would be best if there were an external tool, because the config file is very long, and using for would be very bloated.......... Thanks in advance |
|
| Floor2 exzzz | Posted 2009-01-19 11:53 |
| 初级用户 Posts 167 Credits 194 | |
|
Using for wouldn't be bloated, would it?
Is every line in the config file a variable that needs to be set? |
|
| Floor3 mcubird | Posted 2009-01-19 11:58 |
| 初级用户 Posts 17 Credits 40 | |
|
Not every line is a parameter......
|
|
| Floor4 exzzz | Posted 2009-01-19 12:10 |
| 初级用户 Posts 167 Credits 194 | |
|
If the file doesn't involve anything confidential, I suggest posting it here as an attachment and then listing your requirements clearly, otherwise people reading it will be completely confused...
|
|
| Floor5 netbenton | Posted 2009-01-19 12:23 |
| 银牌会员 Posts 752 Credits 1,916 From 广西 | |
|
call :sub
... ... goto :eof :sub for /f "skip=number of lines" %%a in ('file') do (set var=%%a&goto :eof) ::this can fetch one line set n=1 for /f "skip=number of lines" %%a in ('file') do (set /a n+=1&set var!n!=%%a&if !n!=4 goto :eof) ::this can fetch 4 consecutive lines after the specified line Also, if there are multiple lines, such as 1 55 88 1223... that need to be processed, you can first store the corresponding lines as variables, set /a n+=1&if !n!==55 set "_var!n!=%%a" then for /f %%a in ('set _var') do (perform operations...) or !_var55! !_var88! !_var1223! will be the contents of those specified lines [ Last edited by netbenton on 2009-1-19 at 12:42 ] |
|
| Floor6 mcubird | Posted 2009-01-19 12:23 |
| 初级用户 Posts 17 Credits 40 | |
|
gawk "$3 == 34" val | gawk "/False/ {print $1,$2}" | gawk "$1 > %GeneralLowerLimit% && $1 < %GeneralUpperLimit%" | gawk -f ArithMetic.txt >> Results.txt
This is a section of the processing program. %GeneralLowerLimit% and %GeneralUpperLimit% are parameters the user needs to configure manually. Right now I have the user modify them in the bat, but I want to make a config text file. The config file is as follows: #GeneralLowerLimit 11 #GeneralUpperLimit 698 |
|
| Floor7 mcubird | Posted 2009-01-19 12:46 |
| 初级用户 Posts 17 Credits 40 | |
|
Thanks to the poster in reply #5, I'll go give it a try
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |