Hi,
I am able to generate a csv file which has 3 columns. But the header is not coming out exactly i.e it doesnot have a comma in between it but the data is getting produced with the comma.
The first line i.e the header is coming out as:-
Counter Number Counterparty1 Counterparty2
where Counter Number is the first column, Counterparty1 is the 2nd and Counterparty2 is the 3rd column
The process that i followed is:-
HEADER1="Counter Number"
HEADER2="Counterparty1"
HEADER3="Counterparty2
HEADER="$HEADER1,$HEADER2,$HEADER3"
Then I am deleting the first line from the csv file and then
echo $HEADER > output1.csv
cat input.csv >> output1.csv
mv output1.csv output.csv
It works , but I know that this is not the correct way. I think it can be done with awk and sed. So can somebody help me to put commas inbetween the headers in the first line of the csv...
Thanks for the reply.
Still it is hard coding in the script giving the header names directly. If that the case then my lines were working fine.
But i want a generic one which puts a comma between the header names i.e the first line of any csv file.
I just want to put a comma in column1, column2 and column3.
I had to generate 10 csv files and may be there can be more than three columns. So hard coding is not the option for me...
Atleast please tell me for the above three columns that I have posted, so that i can get some insight and idea....
Another thing that i can do is, I can delete the spaces between any header names as it comes from a stored procedure, so now if the header becomes..
CounterNumber Counterparty1 Counterparty2
I am able to generate a csv file where the data is coming in all the columns properly from the procedure.I am running the procedure in the shell script. But the header is not able to come in its respective columns. What i see that there is no comma in between the headers in the csv file.
I tried to do it with hard coding it- As i had did shown in the above post.
But i need more generic one because if somebody changes the stored procedure and the number of columns or the name of the columns then the script will fail...