How to freely select one column based on another column data?
Posted: 29 Nov 2017 15:49
Hi All,
I have a following code to do the job as select from any other column data based upon first column data via a criteria (profile as which column):
Here is the sample of echosch_1.txt
T501-08680-0101
T501-08699-0101
O501-08690-0101
And here is the profile_scheme.txt
Mockup , QA_Infra , NAR_Infra , MY_Prof , US_Prod
T501-08680-0100, T501-08815-0100, T501-08665-0100, T501-01110-0100, T501-04440-0100
T501-08680-0101, T501-08815-0101, T501-08665-0101, T501-01110-0101, T501-04440-0101
T501-08680-0102, T501-08815-0102, T501-08665-0102, T501-01110-0102, T501-04440-0102
T501-08680-0103, T501-08815-0103, T501-08665-0103, T501-01110-0103, T501-04440-0103
no_gen, no_gen, no_gen, no_gen, no_gen
T501-08699-0100, T501-08700-0100, T501-08681-0100, T501-02220-0100, T501-05550-0100
T501-08699-0101, T501-08700-0101, T501-08681-0101, T501-02220-0101, T501-05550-0101
no_sl, no_sl, no_sl, no_sl, no_sl
O501-08690-0100, T501-08788-0100, T501-08658-0100, T501-03330-0100, T501-06660-0100
O501-08690-0101, T501-08788-0101, T501-08658-0101, T501-03330-0101, T501-06660-0101
O501-08690-0102, T501-08788-0102, T501-08658-0102, T501-03330-0102, T501-06660-0102
no_fk, no_fk, no_fk, no_fk. no_fk
So if "%prof%"=="QA_Infra", then it will select
T501-08815-0101
T501-08700-0101
T501-08788-0101
as output to sch_pack_1.txt
And it works fine for different profile. But there is a limitation for this. I only based upon the first column then select the rest column.
Now the new requirement is asking more flexible. It is not only based upon the first column. It can be any column (for the source data) then select the relative column based upon the profile as output...
Say my new echosch_1.txt is as below
T501-04440-0103
T501-05550-0101
T501-06660-0102
if "%prof%"=="QA_Infra", then it will select
T501-08815-0103
T501-08700-0101
T501-08788-0102
Any thoughts?
Thanks
I have a following code to do the job as select from any other column data based upon first column data via a criteria (profile as which column):
Code: Select all
call C:\auto_pkg_build\Scripts\scheme_replace\get_src.cmd
set prof=%prof: =%
if "%prof%"=="QA_Infra" goto QA_Infra
if "%prof%"=="NAR_Infra" goto NAR_Infra
if "%prof%"=="US_Prod" goto US_Prod
if "%prof%"=="MY_Prof" goto MY_Prof
:QA_Infra
(for /F "tokens=2 delims=, " %%I IN ('findstr /B /g:echosch_1.txt profile_scheme.txt') do echo %%I)>sch_pack_1.txt
goto end
:NAR_Infra
(for /F "tokens=3 delims=, " %%I IN ('findstr /B /g:echosch_1.txt profile_scheme.txt') do echo %%I)>sch_pack_1.txt
goto end
:MY_Prof
(for /F "tokens=4 delims=, " %%I IN ('findstr /B /g:echosch_1.txt profile_scheme.txt') do echo %%I)>sch_pack_1.txt
goto end
:US_Prod
(for /F "tokens=5 delims=, " %%I IN ('findstr /B /g:echosch_1.txt profile_scheme.txt') do echo %%I)>sch_pack_1.txt
goto end
:end
Here is the sample of echosch_1.txt
T501-08680-0101
T501-08699-0101
O501-08690-0101
And here is the profile_scheme.txt
Mockup , QA_Infra , NAR_Infra , MY_Prof , US_Prod
T501-08680-0100, T501-08815-0100, T501-08665-0100, T501-01110-0100, T501-04440-0100
T501-08680-0101, T501-08815-0101, T501-08665-0101, T501-01110-0101, T501-04440-0101
T501-08680-0102, T501-08815-0102, T501-08665-0102, T501-01110-0102, T501-04440-0102
T501-08680-0103, T501-08815-0103, T501-08665-0103, T501-01110-0103, T501-04440-0103
no_gen, no_gen, no_gen, no_gen, no_gen
T501-08699-0100, T501-08700-0100, T501-08681-0100, T501-02220-0100, T501-05550-0100
T501-08699-0101, T501-08700-0101, T501-08681-0101, T501-02220-0101, T501-05550-0101
no_sl, no_sl, no_sl, no_sl, no_sl
O501-08690-0100, T501-08788-0100, T501-08658-0100, T501-03330-0100, T501-06660-0100
O501-08690-0101, T501-08788-0101, T501-08658-0101, T501-03330-0101, T501-06660-0101
O501-08690-0102, T501-08788-0102, T501-08658-0102, T501-03330-0102, T501-06660-0102
no_fk, no_fk, no_fk, no_fk. no_fk
So if "%prof%"=="QA_Infra", then it will select
T501-08815-0101
T501-08700-0101
T501-08788-0101
as output to sch_pack_1.txt
And it works fine for different profile. But there is a limitation for this. I only based upon the first column then select the rest column.
Now the new requirement is asking more flexible. It is not only based upon the first column. It can be any column (for the source data) then select the relative column based upon the profile as output...
Say my new echosch_1.txt is as below
T501-04440-0103
T501-05550-0101
T501-06660-0102
if "%prof%"=="QA_Infra", then it will select
T501-08815-0103
T501-08700-0101
T501-08788-0102
Any thoughts?
Thanks