vsql writes CRLF at the end of output

152 views Asked by At

I'm using vsql to load vertica table into csv file:

vsql -c "select * from ..." ... -o file.csv

I was surprised when I saw windows-like CRLF symbols at the end of the output file. It doesn't match to record or field separators because I use other symbols for it.

Is there any way to change behavior of vsql? In the ideal case, I would like the file to end with the last value of the last column, without any CR or LF symbols at the end.

NB Question is about setting vsql, without using other program to remove symbols from the output.

1

There are 1 answers

2
Walter A On

When you want to use use a line-oriented tool, you need to parse the last line. Removing the \r character on the last line is possible with

 sed '$ s/^$//' file.csv > newfile.csv

The problem is that the newline character that you do not see the new line character. The answer is replacing it by another character that is not part of your normal data.

 tr '\n' '\001' < file.csv | sed 's/..$//' | tr '\001' '\n'