vsql在输出末尾写入CRLF [英] vsql writes CRLF at the end of output
问题描述
我正在使用 vsql
将vertica表加载到csv文件中:
I'm using vsql
to load vertica table into csv file:
vsql -c "select * from ..." ... -o file.csv
当我在输出文件末尾看到类似Windows的CRLF符号时,我感到很惊讶。它与记录或字段分隔符不匹配,因为我为此使用了其他符号。
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.
有什么方法可以改变vsql的行为吗?在理想情况下,我希望文件以最后一列的最后一个值结尾,结尾不带任何CR或LF符号。
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 问题是关于设置vsql,而不使用其他程序从输出中删除符号。
NB Question is about setting vsql, without using other program to remove symbols from the output.
推荐答案
何时使用使用面向行的工具时,您需要解析最后一行。
可以通过以下方式删除最后一行的 \r
字符:
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'
这篇关于vsql在输出末尾写入CRLF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!