Scenario 1: Multiple replacements and column filtering
This following Job searches and replaces various typos and defects in a csv file then
operates a column filtering before producing a new csv file with the final
output.
![UseCasetReplace1.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/UseCasetReplace1.png)
-
Drop the following components from the Palette onto the design workspace: tFileInputDelimited, tReplace,
tFilterColumn and tFileOutputDelimited. -
Connect the components using Main Row
connections via a right-click each component. -
Select the tFileInputDelimited component and
set the input flow parameters.
![UseCasetReplace2.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/UseCasetReplace2.png)
-
The File is a simple csv file stored
locally. The Row Separator is a carriage return
and the Field Separator is a semi-colon. In the
Header is the name of the column, and no
Footer nor Limit are to be set. -
The file contains characters such as:
*t, .
or
Nikson
which we want to turn intoNixon
, and
streat
, which we want to turn intoStreet
.
![UseCasetReplace3.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/UseCasetReplace3.png)
-
The schema for this file is built in also and made of four columns of various
types (string or int). -
Now select the tReplace component to set the
search & replace parameters.
![UseCasetReplace4.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/UseCasetReplace4.png)
-
The schema can be synchronized with the incoming flow.
-
Select the Simple mode check box as the
search parameters can be easily set without requiring the use of regexp. -
Click the plus sign to add some lines to the parameters table.
-
On the first parameter line, select Amount as InputColumn. Type “.” in the Search field, and
“,” in the Replace
field. -
On the second parameter line, select Street as InputColumn. Type “streat” in the Search field,
and “Street” in the Replace field. -
On the third parameter line, select again Amount as
InputColumn. Type “$” in the Search field, and
“£” in the Replace field. -
On the fourth paramater line, select Name
as InputColumn. Type “Nikson” in the Search field,
and “Nixon” in the Replace field. -
On the fifth parameter line, select Firstname as
InputColumn. Type “*t” in the Search field, and
replace them with nothing between double quotes. -
The advanced mode isn’t used in this scenario.
-
Select the next component in the Job, tFilterColumn.
![UseCasetReplace5.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/UseCasetReplace5.png)
-
The tFilterColumn component holds a schema
editor allowing to build the output schema based on the column names of the
input schema. In this use case, add one new column named empty_field and change the order of the input schema columns to
obtain a schema as follows: empty_field, Firstname, Name, Street,
Amount. -
Click OK to validate.
![Use_Case_tReplace6.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/Use_Case_tReplace6.png)
-
Set the tFileOutputDelimited properties
manually. -
The schema is built-in for this scenario, and comes from the preceding
component in the Job. -
Save the Job and press F6 to execute
it.
![UseCasetReplace7.png](https://resources.talendskill.com/document/talend-open-studio-for-esb/version-6x/org.talend.help_6.5.1.20180115_1708/images/UseCasetReplace7.png)
The first column is empty, the rest of the columns have been cleaned up from the
parasitical characters, and Nikson was replaced with
Nixon. The street column was moved and the
decimal delimiter has been changed from a dot to a comma, along with the currency
sign.