ODIExperts.com

The blog for Oracle Data Integrator ( ODI )

Removing Special character using Jython script

This post describes a simple method to remove a single or more special character using Jython script

My source flat file had this special character ( ” )

Image

To remove such special character from ODI without running Unix script or other scripts , Please follow this simple ODI procedure to remove such special character using Jython script.

Image

Image

PROCEDURE – REMOVE SPECIAL CHARACTER IN FILE

STEP – REMOVE

source_file = open(‘D:/xp_odi/oracledi/demo/file/pacs08.csv’, ‘r’)
temp_file = open(‘D:/xp_odi/oracledi/demo/file/pacs08_new.csv’, ‘w’)
count_record=source_file.readline()
while count_record :
s=count_record.replace(‘”‘,”)
temp_file.write(s)
count_record=source_file.readline()
temp_file.close()
source_file.close()

STEP – MOVE FILE

OdiFileMove -FILE=D:/xp_odi/oracledi/demo/file/pacs08_new.csv -TOFILE= D:/xp_odi/oracledi/demo/file/pacs08.csv

In the first part of the script

  • source_file = open(‘D:/xp_odi/oracledi/demo/file/pacs08.csv’, ‘r’)

Iam opening my source file in the Read mode

  • temp_file = open(‘D:/xp_odi/oracledi/demo/file/pacs08_new.csv’, ‘w’)

Here iam defining the Temporary file in the Writable mode

  • count_record=source_file.readline()

Counting the Number of records in the file

  • while count_record :s=count_record.replace(‘”‘,”)temp_file.write(s)count_record=source_file.readline()

Here for each record , iam replacing the special character (“) with null and temp_file.write(s) writes in the target file

Finally after the complete tranfere i move the temp file to source so that we dont need to make any changes to the source.

Run the ODI Procedure and the special character will be removed and final Source file will be

Image

Solution 2 – Suppressing at the ODI Datastore level [ Easiest solution]

image

Under the required data store – in Text Delimiter provide  the Special Character and the special character will be suppressed while loading into the target .As for my  example i have  provide the semicolon in the Text Delimiter.

The File is still there with the special character but  this is the easiest solution.

image

Leave a Reply

Required fields are marked *.


This site uses Akismet to reduce spam. Learn how your comment data is processed.