Solved automation of renaming input file names in a parameter file.

June 27, 2012 at 02:24:23
Specs: Windows XP
Hi Matt,
I have a parameter file with 3 input file names,these input files arrive @one folder,and we have to manually go and edit the 3input filename which has arrived in the location.How can i do it using batch script?

See More: automation of renaming input file names in a parameter file.

Report •


✔ Best Answer
July 4, 2012 at 12:53:07
ok, first, in your example above, the tax auth id is not consistant with some other subsequent parameter values which look like they should match:

$$TXAUTH_ID=090290000

$PMSessionLogFile=s_m_STD_FRMT_CNTRL_KEY_CREATE_090210000.log
$BadFile1=shortcut_to_std_frmt_prpty_cntrl_090210000.bad


[s_m_STG_PRP_090000000_MULTI_A]
$InputFile3=FL.090210000.EDE.00055.A.D011112.T1715.TXT
$InputFile1=FL.090210000.EDE.00921.A.D011112.T1547.TXT
$InputFile2=FL.090210000.EDE.02550.A.D011112.T1905.TXT


$PMSessionLogFile=s_m_STG_PRP_090210000_MULTI_A.log
$BadFile1=shortcut_to_std_frmt_seq_090210000.bad
$BadFile2=shortcut_to_std_frmt_prpty_090210000.bad
$BadFile3=std_frmt_lien_assess_exmpt_090210000.bad

$PMSessionLogFile=s_m_UPDT_LOAD_TO_STD_PRPTY_DT_090210000.log
$BadFile1=UPDT_LOAD_TO_STD_PRPTY_DT_090210000.bad

in this case, 29 (tax auth) versus 21 in these other parameters.
$$TXAUTH_ID=090290000
and the others like: _090210000.bad

Is this actually the case? I would assume (as you mentioned, but it went past me) that tax auth comes from the second "dot" portion of the inputfilename assigned to that parm file (like FL.090500000.EDE.00055.A.D122111.T4537.TXT)
So far I have noted 4 of these values (all following the .090): 50,64,21 and 29. I might assume that these are 4 of the values and there is a fifth, and the five parm files are based on these keys. If this is the case, which key associates with which parmfilename? and just out of curiosity, what is the fifth key value?
Another thing, the 3 inputfile lines are to be inserted rather than appended, (right?) which muddies things up a bit more. Now another loop is required to read and write each file, substituting those three $inputfile lines following the string
[s_m_STG_PRP_090000000_MULTI_A]
(replace next three lines with current file data)
Please advise me of all this, whether I'm right or wrong in all my assumptions.
AND, one other thing I noticed, the filenames seem to be consistant in this regard:
$Inputfile3=FL...00055.A.D0...
$Inputfile1=FL...00921.A.D0...
$InputFile2=FL...02550.A.D0...

ps: my last script assumed that you would create a file called parmbase, but I neglected to advise you to create that file (my bad!). But that's irrelevant at this point, things have changed. I'll make another stab when I know the answers to all my above guesses and queries.



#1
June 27, 2012 at 23:13:21
Does your parameter file look like:

thisfile
thatfile
somefile


?


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
July 1, 2012 at 09:31:31
$DBConnectionSource= DB2D
$DBConnectionTarget= DB2D
$DBConnectionSourceProd= DB2P
$$LIBRARY= CSS
$$TXAUTH_ID=090500000
$$PROP_STAT_KEY=1
$$PRCSS_TYP=PRP
$$FILE_DATA_TYP=7
$$FILE_TYP=F
$$LOT_POPULATE=Y
$$BLOCK_POPULATE=Y
[s_m_STD_FRMT_CNTRL_KEY_CREATE]
$InputFile1=KEY_CREATE.txt
$DBConnectionTarget=Zseries_DB2P
$PMSessionLogFile=s_m_STD_FRMT_CNTRL_KEY_CREATE_090500000.log
$BadFile1=shortcut_to_std_frmt_prpty_cntrl_090500000.bad
[s_m_STG_PRP_090000000_MULTI_A]
$InputFile3=FL.090500000.EDE.00055.A.D122111.T4537.TXT
$InputFile1=FL.090500000.EDE.00921.A.D122111.T4428.TXT
$InputFile2=FL.090500000.EDE.02550.A.D122111.T4737.TXT

Above is the parameter file which we are using,we need automatethis parameter file inputs,we will be getting different agencies at a time and we have created 5 parameter file instance but instead of manuall going nd editing the file ,I need to automateit.
These are the sample agengies input file : 1)$InputFile3=FL.090640000.EDE.00055.A.D011112.T2452.TXT
$InputFile1=FL.090640000.EDE.00921.A.D011112.T2338.TXT
$InputFile2=FL.090640000.EDE.02550.A.D011112.T2641.TXT

2)$InputFile3=FL.090210000.EDE.00055.A.D011112.T1715.TXT
$InputFile1=FL.090210000.EDE.00921.A.D011112.T1547.TXT
$InputFile2=FL.090210000.EDE.02550.A.D011112.T1905.TXT
How to do this using windows scripts?


Report •

#3
July 1, 2012 at 13:11:42
maybe something like this, but I don't know how you would determine which incoming file is #1, #2, etc.:

@echo off & setlocal enabledelayedexpansion
set c=2
copy /y parmbase parmfile
for %%a in ("\incoming\FL*.txt") do
set /a z="c%%3"+1
set /a c+=1
>>%parmfile% echo $inputfile!z!=%%a
)

I had to make a whole slew of ASSumptions, (such as the file-order being 3,1,2) so this prototype is full of holes.


Report •

Related Solutions

#4
July 2, 2012 at 23:06:46
Hi nbrane,
Thanks for your effort and reply ,I tried the above code...its not working,may be i have not given you complete details,please see the complete scenario and suggest me a code.
Below are the 5 parmeter files:
wf_STG_PRP_MULTI_A
wf_STG_PRP_MULTI_A_tmp_01
wf_STG_PRP_MULTI_A_tmp_02
wf_STG_PRP_MULTI_A_tmp_03
wf_STG_PRP_MULTI_A_tmp_04

each parameter file has 3 input file and it has to get automaticallys replaced
with the newly arriving files.At a time we might get 10-15 agencies,each agency has 3source files,so if 10 agency comes,then its 10*3=30 input files we get
in the particular location say C:/Source files.these source files should get replaced with 3 input files in order,like first 3 files should go to one parm file and next 3 to next parmfile and likewise


We should also replace the $$TXAUTH_ID with a agency number which is a 9 digit number presnt in the input file name.
The file order can be 1,2,3.


Report •

#5
July 2, 2012 at 23:49:57
When you say "newly arriving files", how do you determine synchronization? Files may be coming in all the time, and not necessarily in chronolical order. Does the file's name, arrival time (very ambiguous/undependable) or its date, determine its priority? Once that hurdle is crossed, then it's a matter of distributing the filenames, in sets of three, to the five parm files. My take is: incoming 1-3 > parm1, incoming 4-6 > parm2, incoming 7-9 > parm3, incoming 10-12 > parm4, incoming 13-15 > parm5; then repeat sequence. So my problem is how to determine which file is "1-3", "4-6" etc. The file's name or its date should be designed to make it synchronous with your system. (Or maybe I'm way off orbit, Lol!). Never, ever, depend on transfer timing to determine logistics!!! Your IT guys will, I feel sure, vouch for that. Name or date the file to set its precedence. Pls let me know the incomfing file's specifics: name, date (or a facsimile, just to get the idea...)


Report •

#6
July 3, 2012 at 05:23:38
We can do it this way,copy the newly arriving files to one folder,sort it by name ,so u get the order .

Report •

#7
July 3, 2012 at 15:08:37
ok, I think I understand your situation. Here's another stab at the solution. Note that "parmbase" is all but the last three lines of your given parmfile. Are the five parmfiles identical (other than the "$inputfile" lines), or do they have different content? If they're different, you would need an outer loop to do each one.
parmbase file:
$DBConnectionSource= DB2D
$DBConnectionTarget= DB2D
$DBConnectionSourceProd= DB2P
$$LIBRARY= CSS
$$TXAUTH_ID=090500000
$$PROP_STAT_KEY=1
$$PRCSS_TYP=PRP
$$FILE_DATA_TYP=7
$$FILE_TYP=F
$$LOT_POPULATE=Y
$$BLOCK_POPULATE=Y
[s_m_STD_FRMT_CNTRL_KEY_CREATE]
$InputFile1=KEY_CREATE.txt
$DBConnectionTarget=Zseries_DB2P
$PMSessionLogFile=s_m_STD_FRMT_CNTRL_KEY_CREATE_090500000.log
$BadFile1=shortcut_to_std_frmt_prpty_cntrl_090500000.bad
[s_m_STG_PRP_090000000_MULTI_A]

This file is NOT altered, but is used as the "base" for appending the three $input lines.
Here's the batchfile, which appends a set of three lines labeled as 3,1,2 in the
$inputfile lines of the five parmfiles.
@echo off & setlocal enabledelayedexpansion
set parm=wf_STG_PRP_MULTI_A
:this sets up for the pattern 3,1,2,3,1,2...
set c=2
set x=0
set outputparm=!parm!
:this puts the base (lines 1-17) into the current parm file.
copy /y parmbase !outputparm!
:replace "incoming" with your actual directory in the foll. line
for /f "tokens=*" %%a in ('dir /b /o:n ".\incoming\FL*.txt"') do (
set /a z="c%%3"+1
set /a c+=1
>>!outputparm! echo $inputfile!z!=%%a
if !z! equ 2 (
set /a x+=1
set outputparm=!parm!_tmp_0!!x!
copy /y parmbase !outputparm!
)
)
:move FL*.txt .\oldfiles
:end

You need to either delete the files between deliveries, or move/rename them, so the script won't keep picking up old names. That's what the "move" does if you enable it.


Report •

#8
July 4, 2012 at 00:07:06
Hi nbrane,
Thanks a lot,very useful code.I am new to batch scripting,actually I am working on data warehousing and this work was assigned to me before last month.
I searched on google,i could find only basics of batch script but not the code which i was expecting.To be frank ,i was too much scared whether i can finish it by july 5th.
But today i have hopes i can do it,with ALL your help.Below is the complete parmfile content,all the five parmfiles are identical except the $inputfile and the $$TXAUTH_ID,which has to be replaced.



Report •

#9
July 4, 2012 at 12:53:07
✔ Best Answer
ok, first, in your example above, the tax auth id is not consistant with some other subsequent parameter values which look like they should match:

$$TXAUTH_ID=090290000

$PMSessionLogFile=s_m_STD_FRMT_CNTRL_KEY_CREATE_090210000.log
$BadFile1=shortcut_to_std_frmt_prpty_cntrl_090210000.bad


[s_m_STG_PRP_090000000_MULTI_A]
$InputFile3=FL.090210000.EDE.00055.A.D011112.T1715.TXT
$InputFile1=FL.090210000.EDE.00921.A.D011112.T1547.TXT
$InputFile2=FL.090210000.EDE.02550.A.D011112.T1905.TXT


$PMSessionLogFile=s_m_STG_PRP_090210000_MULTI_A.log
$BadFile1=shortcut_to_std_frmt_seq_090210000.bad
$BadFile2=shortcut_to_std_frmt_prpty_090210000.bad
$BadFile3=std_frmt_lien_assess_exmpt_090210000.bad

$PMSessionLogFile=s_m_UPDT_LOAD_TO_STD_PRPTY_DT_090210000.log
$BadFile1=UPDT_LOAD_TO_STD_PRPTY_DT_090210000.bad

in this case, 29 (tax auth) versus 21 in these other parameters.
$$TXAUTH_ID=090290000
and the others like: _090210000.bad

Is this actually the case? I would assume (as you mentioned, but it went past me) that tax auth comes from the second "dot" portion of the inputfilename assigned to that parm file (like FL.090500000.EDE.00055.A.D122111.T4537.TXT)
So far I have noted 4 of these values (all following the .090): 50,64,21 and 29. I might assume that these are 4 of the values and there is a fifth, and the five parm files are based on these keys. If this is the case, which key associates with which parmfilename? and just out of curiosity, what is the fifth key value?
Another thing, the 3 inputfile lines are to be inserted rather than appended, (right?) which muddies things up a bit more. Now another loop is required to read and write each file, substituting those three $inputfile lines following the string
[s_m_STG_PRP_090000000_MULTI_A]
(replace next three lines with current file data)
Please advise me of all this, whether I'm right or wrong in all my assumptions.
AND, one other thing I noticed, the filenames seem to be consistant in this regard:
$Inputfile3=FL...00055.A.D0...
$Inputfile1=FL...00921.A.D0...
$InputFile2=FL...02550.A.D0...

ps: my last script assumed that you would create a file called parmbase, but I neglected to advise you to create that file (my bad!). But that's irrelevant at this point, things have changed. I'll make another stab when I know the answers to all my above guesses and queries.


Report •

#10
July 5, 2012 at 01:19:29
I am sorry for the confusion nbrane,I will answer all your questions step by step
1)It is the 9 digit agency number which should be replaced with all the other 9 digits in the parameter file(except for
[s_m_STG_PRP_090000000_MULTI_A] and $LookupFile1=FL_090000000_Agency_Lookup.txt)these two parameters are static in all files.
For example if agency number is 090210000,then the taxauthid is also 090210000 and the input files should also have FL.090210000...,
the tax auth id is consistent,I have wrongly mentioned in my first example as taxauth_id=090290000 and the other parameters with 090210000.plz ignore it
To be more precise,the whole parameter file should get replaced with the same 9digit depending on the input files(except for
[s_m_STG_PRP_090000000_MULTI_A] and $LookupFile1=FL_090000000_Agency_Lookup.txt).
If the input files are of agency number say FL.090500000.........
then the whole parameter file should get replaced with this number:090500000(except for
[s_m_STG_PRP_090000000_MULTI_A] and $LookupFile1=FL_090000000_Agency_Lookup.txt),but we mainly concentrate on replacing of input files and taxuthid.

For your reference I will attach 2 parmeter file details,so that you can analyse.
2)It is not that we get only five agencies at a time,we might get
more than 5 agencies or less than 5 also.for example we might get 9agencies also at a time i.e 9*3 inputfiles=27files,as per your last code its
creating the parmfiles depending on the no of inputfiles correctly,for 3 inputfiles one parameter file,no issue over there,only the remaining contents should be displayed.
In our project we have created 5 workflows to run,for one workflow,one parameter file is called.we will wait for the 5 workflows to complete and
then call the rest.This wait procedure we are trying to do it at informatica level.I just gave an example of four agencies,for your reference.
Even i dont know which will be the fifth agency,because we have 45 agencies and out of 45 we may get 6 or 10 or 11 agencies files at a time.

3)Yes ,the 3 inputfile lines are to be inserted rather than appended.

4)your right the filenames seem to be consistant in this regard:
$InputFile3=FL.090......EDE.00055.A.D011112.T1715.TXT
$InputFile1=FL.090......EDE.00921.A.D011112.T1547.TXT
$InputFile2=FL.090......EDE.02550.A.D011112.T1905.TXT

BUT
if you look at the last 5 characters before TXT,u will find the difference:
$InputFile3=FL.090640000.EDE.00055.A.D011112.T2452.TXT
$InputFile1=FL.090640000.EDE.00921.A.D011112.T2338.TXT
$InputFile2=FL.090640000.EDE.02550.A.D011112.T2641.TXT


i.e above u can see it has T1715 for inputfile3 and below it is T2452 for input file3,This is the byte length which differs from file to file.
So we need to replace the whole filename instead replacing only 9digit agency number.
For other parameters only 9digit can be replaced.(except for
[s_m_STG_PRP_090000000_MULTI_A] and $LookupFile1=FL_090000000_Agency_Lookup.txt)these two parameters are static in all files.

Below is the code for 2 parameter files,please look at it and you will understand:

Please advice me what needs to be done,we are mainly concerned on input filenames and Taxauthid replacement.There is only one day left for me to submit it.Please do the needful and thanks for your reply.


Report •

#11
July 5, 2012 at 10:29:55
Ah! do I get a bonus, or commission? (Lol, just kidding). This one creates the whole file each time using wfcreate. There's prob'ly a better/more efficient way.

@echo off & setlocal enabledelayedexpansion
set parm=wf_STG_PRP_MULTI_A
:set parm=wf
:this sets up for the pattern 3,1,2,3,1,2...
set c=2
set x=0
set outputparm=!parm!
for /f "tokens=*" %%a in ('dir /b /o:n ".\FL*.txt"') do (
:echo %%a
set /a z="c%%3"+1
set /a c+=1
set t!z!=$InputFile!z!=%%a
if !z! equ 2 (
set f=%%a
set f=!f:~6,2!
:note this could be an external batchfile, just use: call wfcreate !f! (ie: no colon in ft)
call :wfcreate !f! "!t3!" "!t1!" "!t2!"
set /a x+=1
set outputparm=!parm!_tmp_0!!x!
)
)
:move FL*.txt .\oldfiles
goto :eof

:wfcreate
:@echo off & setlocal
>!outputparm! (
echo [Global]
echo $DBConnectionSource=Zseries_DB2D
echo $DBConnectionTarget=Zseries_DB2D
echo $DBConnectionSourceProd=Zseries_DB2P
echo $$LIBRARY=LAS_CSS
echo $$TXAUTH_ID=090%10000
echo $$PROP_STAT_KEY=1
echo $$PRCSS_TYP=PRP
echo $$FILE_DATA_TYP=7
echo $$FILE_TYP=F
echo $$LOT_POPULATE=Y
echo $$BLOCK_POPULATE=Y
echo.
echo [s_m_STD_FRMT_CNTRL_KEY_CREATE]
echo $InputFile1=KEY_CREATE.txt
echo $DBConnectionTarget=Zseries_DB2P
:make SURE the following is all on one line!
echo $PMSessionLogFile=s_m_STD_FRMT_CNTRL_KEY_CREATE_090%10000.log
echo $BadFile1=shortcut_to_std_frmt_prpty_cntrl_090%10000.bad
echo.
echo.
echo [s_m_STG_PRP_090000000_MULTI_A]
)
>> !outputparm! (
echo %~2
echo %~3
echo %~4
)
>>!outputparm (
echo.
echo.
echo $LookupFile1=FL_090000000_Agency_Lookup.txt
echo $PMSessionLogFile=s_m_STG_PRP_090%10000_MULTI_A.log
echo $BadFile1=shortcut_to_std_frmt_seq_090%10000.bad
echo $BadFile2=shortcut_to_std_frmt_prpty_090%10000.bad
echo $BadFile3=std_frmt_lien_assess_exmpt_090%10000.bad
echo $$SITUS_STATE=FL
echo.
echo [s_m_UPDT_LOAD_TO_STD_PRPTY_DT]
echo $OutputFile1=UPDT_LOAD_TO_STD_PRPTY_DT.txt
:make SURE the following is all on one line!
echo $PMSessionLogFile=s_m_UPDT_LOAD_TO_STD_PRPTY_DT_090%10000.log
echo $BadFile1=UPDT_LOAD_TO_STD_PRPTY_DT_090%10000.bad
echo.
echo.
echo [s_m_EXCEPTIONS_REPORT]
echo $InputFile1=EXCEPTIONS_CREATE_FF.txt
echo $OutputFile1=090%10000_EXCEPTIONS_DETAILED_REPORT.txt
echo $OutputFile2=090%10000_EXCEPTIONS_SUMMARY_REPORT.txt
echo $PMSessionLogFile=s_m_EXCEPTIONS_REPORT_MANUAL_OR_AUTO.log
echo $BadFile1=sc_EXCEPTIONS_DETAILED_REPORT.bad
echo $BadFile2=sc_EXCEPTIONS_SUMMARY_REPORT.bad
echo $$CNTRL_KEY=
echo $$MANUAL_OR_AUTO=
echo $$I_O_FLG=
echo $$I_O_TXAUTH_ID=
echo $$CC_CNTRL_KEY=
echo $$CC_TXAUTH_ID=
echo $PMTargetFileDir=\\Reisdal01sfil04\GROUP\Everyone.TempStorage
echo.
echo [s_m_STG_INSRT_THRSHLD_LOAD]
echo $PMSessionLogFile=s_m_STG_INSRT_THRSHLD_LOAD_090%10000.txt
)
:end sub wfcreate
:end script


Report •

#12
July 6, 2012 at 04:28:38
Hi nbrane,
ha ha :-)Its a very useful code and working fine,which is very interseting also,actually when i started with batch script,i was feeling very lazy.But
now I am interested in learning the batch script.Please teach me and i am ready to pay for it.Thanks


When i ran your complete code,its creating 9 parmfiles,they are
1)temp
2)w1_
3)w1_50
4)w1_64
5)w2_
6)w2_50
7)w2_64
8)wf_STG_PRP_090000000_MULTI_A
9)wf_STG_PRP_090000000_MULTI_A_tmp_01

Out of these many files,required is only:wf_STG_PRP_090000000_MULTI_A and wf_STG_PRP_090000000_MULTI_A_tmp_01 which has the perfect output,Is there anyway delete all the
other files using batch script.So that we can keep in memory only the required parmfile.

In your code ,I dint get what you meant at the 16th line-:note this could be an external batchfile, just use: call wfcreate !f! (ie: no colon in ft).
I thought I need to create another batch file with wfcreate name and copy the second half of your code to it and run it,I try that way,but my bad..it did not work.

Please suggest what needs to be done in the batch file to delete the
1)temp
2)w1_
3)w1_50
4)w1_64
5)w2_
6)w2_50
7)w2_64


I would really be thankful,if you teach me batch scripts.

thanks,
Vinutha


Report •

#13
July 6, 2012 at 14:50:52
I'll edit my last posted script to skip using the temporary w1,w2 files and have it write directly to your parmfile. I'll take care of "temp" as well.
I prob'ly won't be very good as instructor but I'll try. I'll send my email address to you and you can email any questions you have. Just reading the examples posted on this forum is about the best instruction you can get - there are some very good scripters on here. That's how I picked it up. Also, the best starter is to consult the batch components themselves using /?:
for /?
set /?
if /?

Report •


Ask Question