You may have a flat file and want to get, for each line of this file, the line number.


Steps to get the line number


To get the line number of each line of the flat file, please follow these steps :


Step 1: Create the metadata

In this example, we want to load data from a csv file and to get, for each line, the corresponding  line number.

Here is the csv file :

You need to create the file metadata to reverse this file :



Step 2: Add the line number field

Then, you will use a Computed Field to get the line number.

Right-click on the file node and select New, then Computed Field :

Give it a name (e.g. Line_Number), a Physical Name and a Size and choose the Numeric Type.

Set Ancestor Level Base filed to 0 and Expression field to localPosition().

That's it!

Step 3: Create the associated mapping


Finally, create a mapping to load data from the source flat file and use the new computed field as any other field.

You'll find here more information about Computed Fields.