Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Blank Line at the end of csv file.

EJ5916
7 - Meteor

How can I eliminate the blank line at the bottom of the outputted csv file?  

 

I'm trying to export a very long single string to a csv file.  The data is written in .json format and the client requires the data to be exported into on run on string without any line breaks.  There could be millions of characters in the one string.

 

Sample of string: 

{"SubmitterId": "1017","TransactionDate": "20240401","Purpose": "A","Action": null,"ActionReason": null,"Providers": [ {"Action": "A","ActionReason": null,"SubmitterId": "1017","TransactionId": "OPTESI_1017_29710679010293564","Person": null,"Business": ...

 

The data outputs correctly when I use a csv output tool.  

(each time I try to upload a picture of the formatted output tool it gives me this error: Uploading Output Tool.png resulted in the following error: Error Code: Invalid File Type.   I've tried uploading .jpg, .bmp, .png)  

File Format:  .csv

Delimiters: \n

First row contains field names:  unchecked

Quotes:  Never

Code Page:  ISO 8859-1 Latin I (I've tried them all. )

Line Ending style:  Windows  (I've tried them all)

Write BOM:  Checked (I've tried unchecked)

 

But when I open the newly created file (using NotePad++), all my data is on line 1 as expected but then there is a blank line 2.  This blank line 2 is causing the file to fail for the client on import and they want me to remove it. 

 

The workflow Messages says it wrote1 record. 

 

I've also tried to output to json format, but this creates multiple lines and puts weird characters in the middle of my fields. 

I've tried to output to a .flat file but it has a limit of 65000 characters per line so that doesn't work. 

 

I noticed that other workflows that export to CSV also include a blank line. I've attached a very simple example.

 

How do I get rid of the extra line?  

 

2 REPLIES 2
usmanbashir
11 - Bolide
flying008
14 - Magnetar

Hi, @EJ5916 

 

or you can use python tool to remove the last blank row :

 

def remove_last_line(filename):
    with open(filename) as objFile:
        lines = objFile.readlines()
        last_line = lines[len(lines)-1]
        lines[len(lines)-1] = last_line.rstrip()
    with open(filename, 'w') as objFile:    
        objFile.writelines(lines)

 

Labels