Expandir la barra de logros de la comunidad.

RESUELTAS

Data Extraction Activity - Is it possible to output with a row above the header row showing count of rows in the file?

Avatar

Level 2

Data Extraction Activity - Is it possible to output with a row above the header row showing count of rows in the file? There doesn't seem to be an obvious way of doing this.

I have a requirement to produce a file from Adobe Campaign that contains the number of data rows in the file. See example below.

Temas

Los temas ayudan a categorizar el contenido de la comunidad e incrementan la posibilidad de encontrar contenido relevante.

1 solución aceptada

Avatar

Respuesta correcta de
Community Advisor

Hi @Dandrews2 ,

 

It is possible to get the count of records at the first line of the file.

 

Please follow the below steps after the Data Extraction (File generation).

 

Example Workflow

 

LakshmiPravallika_1-1686213033250.png

 

After the File generation please add these 3 unix commands to add the header to the output file.

 


var result = execCommand('echo "'+vars.recCount+'" > fullpath/temp_file.csv');

 

logInfo("Result"+result);


execCommand('cat '+vars.filename+' >> Path/temp_file.csv');


execCommand('mv fullPath/temp_file.csv '+vars.filename+'');

 

Then the Output file will be generated with the count of records as the first line in the final file.

PFA Screenshot below:

LakshmiPravallika_0-1686212953506.png

 

 

Regards,

Pravallika.

Ver la solución en mensaje original publicado

4 Respuestas

Avatar

Community Advisor

Hi @Dandrews2 

 

You can use the linux command to get the line count and write it to the file as below :-

vars.recCount=100;
vars.filename='sftpFilePath/fileName.CSV';
var result = execCommand('echo "Total Records: ","'+vars.recCount+'" > '+vars.filename+' ');

AkshayAnand_0-1686157348660.png

 

Regards

Akshay

Avatar

Respuesta correcta de
Community Advisor

Hi @Dandrews2 ,

 

It is possible to get the count of records at the first line of the file.

 

Please follow the below steps after the Data Extraction (File generation).

 

Example Workflow

 

LakshmiPravallika_1-1686213033250.png

 

After the File generation please add these 3 unix commands to add the header to the output file.

 


var result = execCommand('echo "'+vars.recCount+'" > fullpath/temp_file.csv');

 

logInfo("Result"+result);


execCommand('cat '+vars.filename+' >> Path/temp_file.csv');


execCommand('mv fullPath/temp_file.csv '+vars.filename+'');

 

Then the Output file will be generated with the count of records as the first line in the final file.

PFA Screenshot below:

LakshmiPravallika_0-1686212953506.png

 

 

Regards,

Pravallika.

Avatar

Level 2

That worked perfectly Pravallika, thank you

Avatar

Employee Advisor

@Dandrews2 ,

Yes, it is possible to output the count of rows in a file using Adobe Campaign.

However, the method to achieve this may vary depending on the specific tools and techniques you are using for data extraction. Here's a general approach you can follow:

  1. Perform the data extraction: Ensure that you have all the necessary columns and data included.
  2. Count the rows: After the extraction is complete, you'll need to count the number of rows in the file. This can be achieved through programming or scripting languages such as Python, Java, or PowerShell, or even using spreadsheet software like Microsoft Excel.

If you're using Python, you can use the pandas library to read the extracted file and get the row count.

Here's an example:

import pandas as pd

df = pd.read_csv('extracted_file.csv')

row_count = len(df)

 

# Add row count to the file

df.loc[-1] = [row_count]  # Insert a new row at the beginning

df.index = df.index + 1  # Shift the index by 1

df = df.sort_index()  # Sort the index

 

# Save the modified file with row count

df.to_csv('output_file.csv', index=False)

 

This code reads the extracted file, counts the rows using len(df), inserts a new row at the beginning with the row count, and saves the modified file with the row count included.

Remember to adjust the code or tools based on your specific requirements and the format of your data extraction.