Nivel 1
Nivel 2
Iniciar sesión en la comunidad
Iniciar sesión para ver todas las insignias
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.
¡Resuelto! Ir a solución.
Los temas ayudan a categorizar el contenido de la comunidad e incrementan la posibilidad de encontrar contenido relevante.
Vistas
Respuestas
Total de me gusta
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
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:
Regards,
Pravallika.
Vistas
Respuestas
Total de me gusta
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+' ');
Regards
Akshay
Vistas
Respuestas
Total de me gusta
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
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:
Regards,
Pravallika.
Vistas
Respuestas
Total de me gusta
That worked perfectly Pravallika, thank you
Vistas
Respuestas
Total de me gusta
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:
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.
Vistas
Respuestas
Total de me gusta
Vistas
me gusta
Respuestas
Vistas
me gusta
Respuestas
Vistas
me gusta
Respuestas