ePrivacy and GPDR Cookie Consent by Cookie Consent Skip to main content

How to create a header in your file using Command Line Interface Code processor

If the data you receive does not have any headers you can add the header row using simple BASH script with echo and cat commands in Command Line Interface Code processor component.

Your script should include 2 steps:

1. Create a file with the headers for the columns using `echo` command: 

`echo ‘column1_name’, `column2_name’, ‘column3_name’ >> out/files/yourfile.csv`

or

`echo ‘column1_name’, `column2_name’, ‘column3_name’ >> out/tables/yourfile.csv`

 

2. Write rows from an input file to the file with the headers:

`cat  in/files/inputfile.csv >> out/files/yourfile.csv`

or

`cat  in/files/inputfile.csv >> out/tables/yourfile.csv`

 

Example

The example below demonstrates how to create a new file with the headers for the table and join it with the table you have. For the purposes of this demonstration, we create the example file ourselves using the script.

#Create example file - table with 5 rows and 2 columns
for num in 1 2 3 4 5
do
  echo $num, $((num*2)) >> out/files/numbers.csv
done

#create file with headers for the columns
echo '"number", multiply_by_two' > out/files/headers.csv

#concatenate rows from numbers.csv file with headers.csv file
cat  out/files/numbers.csv >> out/files/headers.csv`