Urgent Help - Windows Batch Script Required

Dos / Dos
September 14, 2009 at 05:22:43
Specs: Windows XP
Basically my batch script has to do a line count of a file (.txt) and append the value of the result to the end of the following (in parameter file):

I have a parameter file with following contents:
Filename is manohar.prm
Contents are as follows:

[WCPIT_BIO_EDW.WF:w_DDDMD_LNDG_IMS_NONRET_SALES]
$$Cust_RowCount=72648
$$Sales_RowCount=5235998
$$OuletChangeLog_RowCount=931
$$DRM45_RowCount=581
$$Control_RowCount=4495
$$Outl_Subcat_RowCount=100
$$Fac_Subcat_RowCount=149 that has to be updated with rowcounts of a file (Test.txt) at the end of the variables as shown - please help....


See More: Urgent Help - Windows Batch Script Required

Report •


#1
September 14, 2009 at 05:54:57
@echo off & setlocal > manohar.tmp
for /F %%j in ('type "Test.txt" ^| find /C /V ""') do set rowcnt=%%j
for /F "tokens=1-2 delims==" %%j in (manohar.prm) do (
  if "%%j"=="$$Fac_Subcat_RowCount" (
    echo.%%j=%rowcnt%
  ) else (
    if "%%k"=="" (echo.%%j) else (echo.%%j=%%k)
  )
) >> manohar.tmp

The updated file is manohar.tmp; if correct delete the original one and rename.


Report •

#2
September 14, 2009 at 06:22:38
Thank You Very Much IVO.....
Its really helping me a lot.

Well I have few more clarifications required:
a) The record count value is present in a file (rec_cnt.txt) that has a single line in it that contains TRAIL0101 000000000007.
In the above statement TRAIL0101 is repeated value and 000000000007 is the row count, for example the row count is 30 then the value changes to 000000000030.
b) We are suppose to fetch the row count value from rec_cnt.txt ignoring the zeroes and add this value to the parameter file ------->
Now in the parameter file we have many lines - thus we need to search for the line that has a specific phrase like "w_DDDMD_LNDG_IMS_NONRET_SALES" as shown below and then update the count fetched after the '=' sign of $$DRM45_RowCount:-
[WCPIT_BIO_EDW.WF:w_DDDMD_LNDG_IMS_NONRET_SALES]
$$DRM45_RowCount = value that is been fetched.

The requirement is too much - but I need some help.....



Report •

#3
September 14, 2009 at 08:01:18
@echo off & setlocal EnableDelayedExpansion> manohar.tmp
set /P rowcnt=< rec_cnt.txt
set rowcnt=%rowcnt:* =%
for /L %%j in (0,1,80) do if not "!rowcnt:~%%j,1!"=="0" (
  set rowcnt=!rowcnt:~%%j!
  goto :DONE
)
:DONE
for /F "tokens=1-2 delims==" %%j in (manohar.prm) do (
  if "%%j"=="$$DRM45_RowCount" (
    echo.%%j=%rowcnt%
  ) else (
    if "%%k"=="" (echo.%%j) else (echo.%%j=%%k)
  )
) >> manohar.tmp


Report •

Related Solutions

#4
September 14, 2009 at 20:33:37
IVO thanks a lot for your help.....
The code is working perfectly except for a small bug in it which i have explained below:

The file that has the count details (rec_cnt.txt) contains: the information as shown below:
HEADER0101IMS HEALTHXpo Weekly NEW.PROD.RW9305D.WK0933.LINK019.SRCESUPP W2009080210120090831132102ssnyder@us.imshealth.com
TRAIL0101 000000001016 0000000000CKSUM000002819980261
The above text is in a single line in the rec_cnt.txt.

Issue/Bug:
---------------
The manohar.prm file that has the following content:
[WCPIT_BIO_EDW.WF:w_DDDMD_LNDG_IMS_NONRET_SALES]
$$Cust_RowCount=72648
$$Sales_RowCount=5235998
$$OuletChangeLog_RowCount=931
$$DRM45_RowCount=HEALTHXpo Weekly NEW.PROD.RW9305D.WK0933.LINK019.SRCESUPP W2009080210120090831132102ssnyder@us.imshealth.com
$$Control_RowCount=4495
$$Outl_Subcat_RowCount=100
$$Fac_Subcat_RowCount=149
IN the above file content the text in bold is been fetched from the rec_cnt.txt file and been pasted after "$$DRM45_RowCount".
Instead the code has to fetch only the record count details which is part of the text TRAIL0101 000000000007 where 7 is the actual count - so ideally it should something be like this.........
$$DRM45_RowCount = 7

Thanks again - I am sure I nearing to the requirement.


Report •

#5
September 15, 2009 at 06:02:05
Hi IVO,

Would also like to know how to have the batch file executed from Informatica 8.6 to implement the same.
Thanks and regards
Manohar Rao


Report •

#6
September 15, 2009 at 09:19:53
Are you sure the text the line count is catched from is contained in ONE line?

From your post and the behavior of my script it seems the lines are two, the first beginning with HEADER and the other with TRAILER.

What is Informatica 8.6? I'm italian but never heard such application ( by the way Informatica is the Italian word for Information Technology).


Report •

#7
September 15, 2009 at 20:28:37
Thanks for your response IVO.....
Wonderful - you question is perfect but I apologies for providing you an incorrect information. As the HEADER file is in *.001 format I used Notepad to open it which pulled the contents in a single line. Where as when I open the same HEADER file using Wordpad it is in two lines as you said - the first beginning with HEADER and the other with TRAILER.

Well the answer for the other question is:
Informatica is a data integration platform, some of the key characteristics of Informatica that stand out are the
1. ETL (Data Extraction, Transformation and Load) process components and the user interface
2. Metadata Management
3. Wider/Huge amount of data handling.


In addition to the above I have posted another requirement in the same forum:
http://www.computing.net/answers/wi...

Please assist.


Report •

#8
September 16, 2009 at 02:36:03
In the script in Post #3 replace

set /P rowcnt=< rec_cnt.txt
set rowcnt=%rowcnt:* =%

with

for /F "tokens=2" %%j in (rec_cnt.txt) do set rowcnt=%%j

About Informatica 8.6 I can't help as I do not have any exposure to that environment.

About your question regarding unzipping the .gz archives the script is quite easy to code but it depends on the tool used to unzip as there is a lot on the web either commercial or free and each one has different command line parameters.

Take the advice posted: these questions are better handled in the Programming Forum..


Report •

#9
September 16, 2009 at 02:43:08
Fantastic - IVO
Not sure how to thank you.....?

The code is perfect and is just listening to my words now.....
Will revert if I need any clarification.
Do you have any specific email address where I can communicate if I am not able to reach you through this forum?

Thanks Again!
:-)


Report •

#10
September 16, 2009 at 03:31:22
I'll send you a private message with my e-mail address.

Report •

#11
September 16, 2009 at 05:43:35
Hi IVO,

Thanks for your message, in addition to the above requirement there is a small additional task that has to be considered.
The for loop that we have used:
for /F "tokens=2" %%j in (Count.001.head) do set rowcnt=%%j
fetches the row count details from the file Count.001.head, but can we have it modified to search a part of the file name string and consider the file that ends with 0001.head.
For example:
The actual file that has the row count is something like:
NEW.PROD.RW92452.CLI561.WK0933.SUMCOMMA.001.head
The only part that remains unchanged in the above file name is 'SUMCOMMA', so my script has to look into a folder named 'SRC_FILES' that has SUMCOMMA word as a part of the filename with extension 001.head

Ooooof I am really wonder or cannot imagine to have to code such a requirement without your help....
:-)
Thanks and regards
Mano


Report •

#12
September 16, 2009 at 06:47:20
for %%k in (*SUMCOMMA.001.head) do (
   for /F "tokens=2" %%j in (%%k) do set rowcnt=%%j
)

Use the mail address I sent as this thread is dying.


Report •


Ask Question