2

What is the use of Escape char and Text Enclosure in tFileOutputDelimited component and How can we use them??

enter image description here

Thanks in Advance...

Horse_1995
  • 227
  • 5
  • 14

1 Answers1

5

To answer your question, consider the below example from CSV file

bookId,bookname,description,authorname
1,Grammer,book that has details about grammer,author1
2,Special Characters, book that describes about some escape characters like \", punctuations and special characters ,etc.,author2
3,Mathematics, book that has mathematical operations like addition +, subtraction -, multiplication *, division / etc, author3

I have created a simple job like below

enter image description here

In the above sample, character comma "," is the delimiter. But there are some commas in between the data.

The data that is written to CSV file will look like below,

enter image description here

Now When I read the data from that file I will get below data

.------+------------------+-------------------------------------------------------+-------------------------------------.
|                                                       tLogRow_3                                                       |
|=-----+------------------+-------------------------------------------------------+------------------------------------=|
|bookId|bookName          |description                                            |author                               |
|=-----+------------------+-------------------------------------------------------+------------------------------------=|
|1     |Grammer           |book that has details about grammer                    |author1                              |
|2     |Special Characters|book that describes about some escape characters like "| punctuations and special characters |
|3     |Mathematics       |book that has mathematical operations like addition +  | subtraction -                       |
'------+------------------+-------------------------------------------------------+-------------------------------------'

If you notice, some data are missing in the log for "author" column.

This is because of the comma in between the data. To avoid it Text Enclosure option is used. Also there is a escape character in the data, which is \". In the file it will be printed as ". If Text Enclosure has value as """, then you need to escape the character " which is present inside the data. To do this, you have to use Escape char option, like below

enter image description here

Now the output that I got is

enter image description here

When I read this data, I will get data like below,

.------+------------------+-------------------------------------------------------------------------------------------------------+-------.
|                                                                tLogRow_3                                                                |
|=-----+------------------+-------------------------------------------------------------------------------------------------------+------=|
|bookId|bookName          |description                                                                                            |author |
|=-----+------------------+-------------------------------------------------------------------------------------------------------+------=|
|1     |Grammer           |book that has details about grammer                                                                    |author1|
|2     |Special Characters|book that describes about some escape characters like ", punctuations and special characters ,etc.     |author2|
|3     |Mathematics       |book that has mathematical operations like addition +, subtraction -, multiplication *, division / etc.|author3|
'------+------------------+-------------------------------------------------------------------------------------------------------+-------'

If you notice, no data is lost.

Hope this would help you out.

Viki888
  • 2,686
  • 2
  • 13
  • 16
  • hello Viki888, you did not perform any changes to get the output second time.. can you please provide me the changes if u did anything... – Horse_1995 Apr 20 '17 at 09:12
  • 1
    The changes that I did is, i have `enabled the CSV options in the tFileOutputDelimited component` which I have mentioned in my answer. – Viki888 Apr 20 '17 at 09:14
  • Thank u Viki888 .... but when we are using tFixedflowInput component that output is coming.....otherwise (i.e tFileInputDelimited..) it wont produce required result – Horse_1995 Apr 20 '17 at 09:41
  • In that case, for `tFileInputDelimited` you have to enable `CSV options`. – Viki888 Apr 20 '17 at 10:03