0

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.

Vikora
  • 174
  • 1
  • 6
  • 19
  • 1
    Try this: `vsql -c "select * from ..." ... | tr -d '\r' >file.csv` – Lorinczy Zsigmond Sep 05 '17 at 11:17
  • Do you have LF on each line? I think you want to use `tr` to remove all of them. I think removing the `\n` on the last line is a bad idea, different utilities will have problems reading such an "incomplete" file. Do you really want that? – Walter A Sep 05 '17 at 19:52
  • Possible duplicate of [AIX: remove the last symbols (CRLF) from a file](https://stackoverflow.com/questions/46041958/aix-remove-the-last-symbols-crlf-from-a-file) – Walter A Sep 05 '17 at 20:21
  • @WalterA, there is a one line only, because I don't use \r or \n as a record separator. But the data itself can contain \r or \n. – Vikora Sep 06 '17 at 18:39

1 Answers1

1

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'
Walter A
  • 19,067
  • 2
  • 23
  • 43
  • hi! Thanks for you answer. This code `tr '\n' '\001'` changes ALL `\n` symbols, but I need to change just the last one. – Vikora Sep 08 '17 at 13:35
  • 1
    Yes, I did that on purpose. First I change all, so `sed` will think your csv is one long line. With `sed` I can remove the last two characters, and it will operate on the last (only) line. And now I honour your comment by changing back all the `\001` characters that were originally newlines in the middle of the data. – Walter A Sep 08 '17 at 19:10