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.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
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.
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
Views
Replies
Total Likes
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.
That worked perfectly Pravallika, thank you
Views
Replies
Total Likes
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.
Views
Replies
Total Likes