Operating System - HP-UX
1753505 Members
5006 Online
108794 Solutions
New Discussion юеВ

append the output to a .csv format

 
SOLVED
Go to solution
shikhar_1
Regular Advisor

append the output to a .csv format

Hello,

I got stuck while appending the output of command in .csv format at a aprticular column in my .csv file.
Actually i need to create a report for that i have already created the shell script and its output is coming in number suppose "32" and i have to put this number in a excel sheet to a particular location.
Pls help me.

Reagrds,

Shikhar Verma
5 REPLIES 5
Steven Schweda
Honored Contributor

Re: append the output to a .csv format

> Pls help me.

You first. We non-psychics can't see any of
your data, and some of us can't guess what
you wish to do.

What do you have now?

What would you like to get?

Actual examples would probably be more useful
than vague descriptions.

Where are you trying to do this?

uname -a
shikhar_1
Regular Advisor

Re: append the output to a .csv format

Hi,

I am doing it on HP-UX server. My current script is giving me the output which i need to put it in a particular column of excel sheet.

./myscript this script is giving me some o/p
and i wanted to put this o/p in my report file, which is excel file.
shikhar_1
Regular Advisor

Re: append the output to a .csv format

Hi,

My query is that ---
is it possible to redirect the o/p of any shell script to a excel sheet to a particular couln or row?
shikhar_1
Regular Advisor

Re: append the output to a .csv format

Say my text file data is:

15-dec-2008 15-dec-2009
16-dec-2008 16-dec-2009


say my first excel column is:

column1 column2 column3
server1
server2


I want output as below:

column1 | column2 | column3
server1 | 15-dec-2008 | 15-dec-2009
server2 | 16-dec-2008 | 16-dec-2009
Hein van den Heuvel
Honored Contributor
Solution

Re: append the output to a .csv format

Ok Shikar,

you are getting closer to a proper explanation.
IF this exactly describes the problem you can solve it like so:

$ cat > text.txt
15-dec-2008 15-dec-2009
16-dec-2008 16-dec-2009
$ cat > excel.csv
column1 column2 column3
server1
server2
$ awk 'BEGIN { print } 1' text.txt | paste -d' ' excel.csv - | sed 's/ / | /g'
column1 | column2 | column3 |
server1 | 15-dec-2008 | 15-dec-2009
server2 | 16-dec-2008 | 16-dec-2009

First we use AWK to feed a pipe with a blank line and the contents of the text file.
That gets patsted with the excel file using a space, not the default tab, as seperator.
Finally replace each space with a spaced-bar/pipe

I doubt that this will solve the problem though.

You really want to know more about the data. Like whether you know for sure each line is in the right order.
Maybe there is a 'key' column perhaps 'system same' and we should use JOIN, not PASTE

Maybe you should really take a huge step back and revisit how the data comes to be.
Whether the column headers are meaningful and that meanig can be used.
Whether column headers are hardcoded or should/could be generated.
Whether the lines just have order, or have a 'tag'/'key'.

Good luck!
Hein