How to create multiline csv cell through shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create multiline csv cell through shell script?
# 1  
Old 02-13-2013
How to create multiline csv cell through shell script?

Hi,

I have a text like the one given below

Code:
status="Observation 1"
read1="Source rows not load"
read2="Score drop"


I want to create a csv and mail it out in such a way that all three lines will be in a single cell but as three lines.


For ex


Code:
                    Col C1
 
                Observation 1
Row R1       Source Rows not load
                 Score drop

I tried multiple ways But I always end up in getting all three messages in a single line or three different rows.

Any suggestions?

Last edited by Scrutinizer; 02-13-2013 at 07:13 PM.. Reason: code tags
# 2  
Old 02-13-2013
I don't think you can do this kind of formatting in CSV. I would suggest to create a HTML table out of your file data using awk with formatting of your choice.

Here is an example:
Code:
awk -F= ' BEGIN {
                print "<html><body>"
                print "<table border=1>"
                print "<tr><td align=center>"
        } {
                gsub(/"/,X);
                print $2"<br>";
        } END {
                print "</td></tr>"
                print "</table>"
                print "</body></html>"
} ' file

# 3  
Old 02-13-2013
If your loading the file from Excel your required format is:

Code:
"Observation 1
Source Rows not load
Score drop"^M

Where ^M is above is AscII 13 (\r)

this awk script should produce what you want:

Code:
awk -F\" '
/^status=/ { $2="\" $2}
/^read2=/ {$2=$2 "\"\r" }
1' infile

# 4  
Old 02-16-2013
I think MS EXCEL needs the ^M after each line but the last in a multiline cell. Try to make it
Code:
"Observation 1^MSource Rows not load^MScore drop"

I'm sorry I can't test it - this is a MS - free computer.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Multiline html tag parse shell script

Hello, I want to parse the contents of a multiline html tag ex: <html> <body> <p>some other text</p> <div> <p class="margin-bottom-0"> text1 <br> text2 <br> <br> text3 </p> </div> </body> (15 Replies)
Discussion started by: SorcRR
15 Replies

2. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

3. UNIX for Dummies Questions & Answers

Trying To Write File Contents To Specfic .csv Cell

Hi, I'm attempting to write the entire contents of a file to a specific .csv cell. So far have only a nawk one liner that will write a value into a specific .csv cell. Trying to use man page but can't seem to get any farther. Any help would be appreciated. nawk -v r=2 -v c=3 -v val=5 -F,... (7 Replies)
Discussion started by: jimmyf
7 Replies

4. UNIX for Dummies Questions & Answers

How to Create excel file(.csv) using shell script?

Hi, i have shell script which compiles n number of test cases and execute them one by one. i want to create report in excel through script in which two columns namely "test id" and "release".second column have two subcolumns namely compiles and excutes. so i want first column should display test... (15 Replies)
Discussion started by: RamMore123
15 Replies

5. UNIX for Dummies Questions & Answers

multiline comment in shell script

Is thery any way to give comment to multiple line without explicitly specifying # at the begining of each line ? (2 Replies)
Discussion started by: hiten.r.chauhan
2 Replies

6. Shell Programming and Scripting

Extract last cell of csv file

How do I extract the last cell in a column of a csv file using linux shell scripting? Or alternatively, how do I get the number of cells of a csv file? (2 Replies)
Discussion started by: locoroco
2 Replies

7. Shell Programming and Scripting

how to create csv file using shell script

I have a file in multiple directory which has some records in the following format File: a/latest.txt , b/latest.txt, c/latest.txt -> Name=Jhon Age=27 Gender=M Street=LA Road Occupation=Service I want to generate a csv file from the above file as follows File: output.csv -> ... (9 Replies)
Discussion started by: rjk2504
9 Replies

8. UNIX for Advanced & Expert Users

How to add two values in the same cell of CSV file

I need help to create a csv file with Unix command. In csv file, i need to put two values in the same cell. Rite now, whts happening is, if i put 2 values in the same cell, its comming as " asd, zxc" but i want it in different line but in same cell. asd zxc Please reply me ASAP. (1 Reply)
Discussion started by: Prashant Jain
1 Replies

9. Shell Programming and Scripting

get output in each cell from shell script

Hi, I have a code which gives me different values all in a same line. what do i change to make the output have each value in each cell. code: echo $user $firstname $lastname $address done | tee userinfo.xls i want the $user value to be in first cell of excel, $firstname in the... (3 Replies)
Discussion started by: sophos
3 Replies

10. Shell Programming and Scripting

How to edit particular cell of csv file using shell script

I have one csv file and in that I want update particular cell. I know the row and coloumn number for that respective. Please help me... (6 Replies)
Discussion started by: deepak_p86
6 Replies
Login or Register to Ask a Question