How to do the condition in this case...
Moderator: DosItHelp
How to do the condition in this case...
Hi,
I have a text file, either in one line,but the string are separated by space or each line have one string....
say T501-08665-0102 T501-08665-0101 T501-08681-0100 T501-08658-0100
or
T501-08665-0102
T501-08665-0101
T501-08681-0100
T501-08658-0100
Now how can I write a set command based upon the string middle portion and last portion
I would like to have this output as
set vargen=T501-08665-0102
set vargen1=T501-08665-0101
set varsl=T501-08681-0100
set varfk=T501-08658-0100
Basically I do not want mess up the set since the first line and second line belong to same category because they shared the same middle portion as 08665, it might have 3 lines or more having same middle portion,say
T501-08665-0102
T501-08665-0101
T501-08665-0100
in this case,the output would be
set vargen=T501-08665-0102
set vargen1=T501-08665-0101
set vargen2=T501-08665-0100
Is any better way to achieve this issue??
Thanks
I have a text file, either in one line,but the string are separated by space or each line have one string....
say T501-08665-0102 T501-08665-0101 T501-08681-0100 T501-08658-0100
or
T501-08665-0102
T501-08665-0101
T501-08681-0100
T501-08658-0100
Now how can I write a set command based upon the string middle portion and last portion
I would like to have this output as
set vargen=T501-08665-0102
set vargen1=T501-08665-0101
set varsl=T501-08681-0100
set varfk=T501-08658-0100
Basically I do not want mess up the set since the first line and second line belong to same category because they shared the same middle portion as 08665, it might have 3 lines or more having same middle portion,say
T501-08665-0102
T501-08665-0101
T501-08665-0100
in this case,the output would be
set vargen=T501-08665-0102
set vargen1=T501-08665-0101
set vargen2=T501-08665-0100
Is any better way to achieve this issue??
Thanks
Re: How to do the condition in this case...
You used variable names like vargen, varsl and varfk. Are they dependent on the values? And if so, what would happen if we find a value with a middle part other than those that you wrote in your example?
Steffen
Steffen
Re: How to do the condition in this case...
Yes! basically the middle part are related to profile like I posted in other post "How to freely select one column based on another column data? ". However, there are not many variations, around 4 or 5 values which defined the middle part. Probably we can hard-coded the profile related middle portion?
Thanks
Re: How to do the condition in this case...
Sorry but I also didn't understand the requirements in your other thread. Maybe you should wait for Antonio who obviously did.
Steffen
Steffen
Re: How to do the condition in this case...
Thanks Steffen!aGerman wrote: ↑13 Dec 2017 17:46Sorry but I also didn't understand the requirements in your other thread. Maybe you should wait for Antonio who obviously did.
Steffen
I have an alternative way. Actually I have a separate txt file which only hold vargen before I combined them together
say
T501-08665-0102
T501-08665-0101
How can I make set command based upon this txt file
if only one line
T501-08665-0102
then set vargen=T501-08665-0102
if two lines
T501-08665-0102
T501-08665-0101
then set vargen=T501-08665-0102
set vargen1=T501-08665-0101
........
How can we make it?
Re: How to do the condition in this case...
Try that code
Steffen
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set "txtfile=vargen.txt"
set "n="
for /f %%i in ('type "%txtfile%"') do (
set "vargen!n!=%%i"
set /a "n+=1"
)
set vargen
pause
Re: How to do the condition in this case...
Thanks Steffen!! it works!aGerman wrote: ↑14 Dec 2017 19:28Try that codeSteffenCode: Select all
@echo off &setlocal EnableDelayedExpansion set "txtfile=vargen.txt" set "n=" for /f %%i in ('type "%txtfile%"') do ( set "vargen!n!=%%i" set /a "n+=1" ) set vargen pause
How to output into a txt file??
my desired output should looks like
set vargen=T501-08665-0102
set vargen1=T501-08665-0101
I tried as this only got
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set "txtfile=gen_sch_pack_need.txt"
(
set "n="
for /f %%i in ('type "%txtfile%"') do (
set "vargen!n!=%%i"
set /a "n+=1"
)
)
echo set %vargen% >>vargen.txt
set T501-08665-0102
Re: How to do the condition in this case...
Using ECHO redirection as always
Code: Select all
@echo off &setlocal EnableDelayedExpansion
set "txtfile=gen_sch_pack_need.txt"
set "outfile=vargen.txt"
set "n="
>"%outfile%" (
for /f %%i in ('type "%txtfile%"') do (
echo set vargen!n!=%%i
set /a "n+=1"
)
)
Re: How to do the condition in this case...
aGerman wrote: ↑15 Dec 2017 12:19Using ECHO redirection as alwaysCode: Select all
@echo off &setlocal EnableDelayedExpansion set "txtfile=gen_sch_pack_need.txt" set "outfile=vargen.txt" set "n=" >"%outfile%" ( for /f %%i in ('type "%txtfile%"') do ( echo set vargen!n!=%%i set /a "n+=1" ) )