LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   newline not work with my csv (https://www.linuxquestions.org/questions/linux-newbie-8/newline-not-work-with-my-csv-4175456312/)

nicksu 03-31-2013 09:11 PM

newline not work with my csv
 
1 Attachment(s)
Hi,I have a file,content as below:
a
b
c
d

and I want insert the content into a csv form,and used the
"echo ,,`cat file`, >file.csv"
but the csv form turns out to be as below:
Attachment 12175

Can anyone help to make the newline work,and keep the format as the file shows,not shows in one line.

evo2 03-31-2013 10:55 PM

Hi,

what about the following:
Code:

sed 's/$/,/g' < file > file.csv
If that doesn't do what you want (because at this point we can only guess), please be explicit about what you want the output csv file to look like.

Evo2.

nicksu 03-31-2013 11:17 PM

1 Attachment(s)
Quote:

Originally Posted by evo2 (Post 4922439)
Hi,

what about the following:
Code:

sed 's/$/,/g' < file > file.csv
If that doesn't do what you want (because at this point we can only guess), please be explicit about what you want the output csv file to look like.

Evo2.

Attachment 12176Hi,I want it to look like this,thank you for your help

evo2 03-31-2013 11:43 PM

Hi,

Quote:

Originally Posted by nicksu (Post 4922444)
Attachment 12176Hi,I want it to look like this,thank you for your help

I need to see the csv file itself, not how it is rendered in some spread sheet program. Eg what is the output of
Code:

cat --show-nonprinting file.csv
Evo2.

Wim Sturkenboom 04-01-2013 12:04 AM

You need to embed the text in double quotes. The below was tested in a windows environment and shows how you can embed newlines (double quotes highlighted in bold red) as well as commas in csv fields.

csv file
Code:

"a
b
c
d","1,2,3,4"
"x
y
z","0,9,8,7"

The result
Code:

+----+-------------+
| a  | 1,2,3,4    |
| b  |            |
| c  |            |
| d  |            |
+----+-------------+
| x  | 0,9,8,7    |
| y  |            |
| z  |            |
+----+-------------+

Explanation:
unless within double quotes, newlines indicate the end of the records; similar, commas indicated the end of a field

nicksu 04-01-2013 12:41 AM

Quote:

Originally Posted by evo2 (Post 4922450)
Hi,


I need to see the csv file itself, not how it is rendered in some spread sheet program. Eg what is the output of
Code:

cat --show-nonprinting file.csv
Evo2.


[ssh@Nick sf_osshare]$ cat --show-nonprinting t.csv
,,a
b
c
d,
HI,nothing different

evo2 04-01-2013 01:33 AM

Hi,

I thought that Wim's post was the answer...
Quote:

Originally Posted by nicksu (Post 4922470)
[ssh@Nick sf_osshare]$ cat --show-nonprinting t.csv
,,a
b
c
d,
HI,nothing different

Does that file display as you want it to in your spread sheet? If yes, then what is the problem? If no, then please post the contents of the file that does.

Evo2.

PS. Please use [code] tags where appropriate.

nicksu 04-01-2013 03:38 AM

Quote:

Originally Posted by evo2 (Post 4922500)
Hi,

I thought that Will's post was the answer...


Does that file display as you want it to in your spread sheet? If yes, then what is the problem? If no, then please post the contents of the file that does.

Evo2.

PS. Please use [code] tags where appropriate.

Hi,thank you for your help.a printf work,thank you


All times are GMT -5. The time now is 04:19 AM.