换行问题在Linux中移动CSV文件 [英] Line breaking issue to move csv file in Linux

查看:188
本文介绍了换行问题在Linux中移动CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[我已将csv文件移动到具有二进制模式的Linux系统中.一个字段的文件内容被拆分为多行,其注释部分,我需要删除新行,保持相同格式,请在shell命令或perl命令上提供帮助

[I have moved the csv file into Linux system with binary mode. File content of one field is spitted into multiple lines its comment sections,I need to remove the new line , keep the same format, Please help on shell command or perl command

这是三个记录的示例,实际看起来像] 文件的原始内容

here is the example for three records, Actual look like] Original content of the file

[进入Linux后,注释字段被分为4行,我想使注释字段保持相同的格式,但不希望换行符

[After moved into linux, comments field is splitted into 4 lines , i want to keep the comment field in the same format but dont want the new line characters

第一行

第二行

第三行 所有行格式都不应更改" ] 2

Third line all lines format should not change" ]2

推荐答案

正如我在上面的评论中所说,规范尚不清楚,但我怀疑这是您要尝试做的事情.这是一种使用sqlldr将数据加载到Oracle中的方法,其中,字段用双引号引起来,并包含换行符,其中记录的末尾是回车/换行的组合.例如,当数据来自保存为.csv的Excel电子表格时,单元格包含换行符时,就会发生这种情况.

As I said in my comment above, the specs are not clear but I suspect this is what you are trying to do. Here's a way to load data into Oracle using sqlldr where a field is surrounded by double-quotes and contains linefeeds where the end of the record is a combination carriage return/linefeed. This can happen when the data comes from an Excel spreadsheet saved as a .csv for example, where the cell contains the linefeeds.

这是Excel导出为.csv并在gvim中查看的数据文件,并且已打开该选项以显示控制字符.您可以看到换行符为'$'字符,而回车符则为'^M'字符:

Here's the data file as exported by Excel as a .csv and viewed in gvim, with the option turned on to show control characters. You can see the linefeeds as the '$' character and the carriage returns as the '^M' character:

100,test1,"1line1$
1line2$
1line3"^M$
200,test2,"2line1$
2line2$
2line3"^M$

使用infile选项行上的"str"子句来构造这样的控制文件,以设置记录字符的结尾.它告诉sqlldr,十六进制0D(回车或^ M)是记录分隔符(这样,它将忽略双引号内的换行符):

Construct the control file like this using the "str" clause on the infile option line to set the end of record character. It tells sqlldr that hex 0D (carriage return, or ^M) is the record separator (this way it will ignore the linefeeds inside the double-quotes):

LOAD DATA
infile "test.dat" "str x'0D'" 
TRUNCATE
INTO TABLE test
replace
fields terminated by ","  
optionally enclosed by '"'
(
cola char,
colb char,
colc char
)

加载后,数据看起来像这样,并保留了注释字段(我称为colc)中的换行符:

After loading, the data looks like this with linefeeds in the comment field (I called it colc) preserved:

SQL> select *
  2  from test;

COLA                 COLB                 COLC
-------------------- -------------------- --------------------
100                  test1                1line1
                                          1line2
                                          1line3

200                  test2                2line1
                                          2line2
                                          2line3

SQL>

这篇关于换行问题在Linux中移动CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆