Line breaking issue to move csv file in Linux

前端 未结 1 1716
走了就别回头了
走了就别回头了 2020-12-18 16:58

[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 ,

相关标签:
1条回答
  • 2020-12-18 17:30

    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.

    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$
    

    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
    )
    

    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>
    
    0 讨论(0)
提交回复
热议问题