Skip to Content
0

script - merge two files into one

Jun 30, 2017 at 11:34 AM

90

avatar image
Former Member

Hi ,

I have process which take data from .txt files (file_A.txt, file_B.txt).
I'd like to add option at the end of process which marge above files into one file .txt and add to this file additional column with file name.
I tried to do this in script and cmd commnads but without success.

In windows 'commant prompt' below command works but I can't get the same in BODS.

cd C:\test
for /f %a in ('dir /b file_*.txt') do for /f "tokens=*" %b in (%a) do echo %b,%a
>> C:\test\test2\file_final.txt


Maybe you have idea how can I do it in different way

My BODS - 4.2 SP2

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Dirk Venken
Jul 05, 2017 at 09:55 AM
0

If all files are the same format, define the DS file format for the sources, make sure to include the DI_Filename column in the format definition

Create a 2nd file format for the output file, with one additional column.

Build a simple data flow. Use the 1st file format as source in a Query transform, use a wildcard for the file name and map all fields one-to-one. Connect the Query to the 2nd file format and run. The DI_filename column will be populated automatically.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 04, 2017 at 12:41 PM
0

does anybody has any idea?

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jul 05, 2017 at 04:26 PM
0

Create you DF something like below. In QRY_ADD_SOURCE_NAME_1 and QRY_ADD_SOURCE_NAME add additional column as source name in which put the value of your source. Merge them using merge transform then.


capture.png (10.5 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded

If you use a wildcard in the source filename, you don't need a 2nd Query transform, nor a Merge.

The file name can be added automatically by setting the Include file name column in the File Format usage:

0
Former Member

Ohh great point, thanks :)

0
avatar image
Former Member Jul 11, 2017 at 12:49 PM
0

Hi,

thank you for answer - I had idea to built DF which will export data in the last step into one flat file but I thought I can do it in script also. In cmc commands my idea works, in script - probably I missed somewhere " or ' or /
But thanks for help

Regards

Share
10 |10000 characters needed characters left characters exceeded