I have been trying to find a good solution for this seemingly simple task for 2 days, and I'm giving up and posting a thread. I hope someone can help me out!
I'm on HPUX, using sqlplus, mailx, awk, have some other tools available, but can't install stuff that isn't already in place (without a HUGE hassle anyway).
I have a file that is output from a sqlplus query, that is a comma seperated value file of the type:
First task is to create the messag ebody of the email, that I would like to be more readable like the following, with one 'paragraph' for each record or row. This way the email can be printed out and is easy enough to read if there are only a few rows.
If I could put the CSV into a 2 dimensional array I could do something like this in awk:
for (row=2; row<=NR; row+=1)
for (col=1; col<=NF; col+=1)
printf("%s: %s\n",csv[1][col], csv[row][col]);
end
end
But I'm not sure how to get this done properly and simply. I can use awk, sed, and this is all in ksh. There are other tools available too, so if you have an idea shout.
The second part of my problem is that I can't get this to email properly. I found a million examples, but none of them seem to work. We have very stringent rules here, (i work at a power utility) so I can't just install mutt or similar, but I have access to mail, mailx, and sendmail, but I think thats it for mailing purposes. Here's what I've got:
ux2dos list.prt > list.prt.dos
uuencode list.prt.dos list.csv > Attach
cat Body Attach > MessageAndy
mailx -m -s "subject" me@here.com < MessageAndy
Once I get problem 1 figured out, that will be the body of the message, while the attached file will be the original CSV file so if there are a ton of records it can be opened and sorted/manipulated in excel.
But the current code for mailing stuff gives me a test body of the message followed by a seemingly incorrectly processed uuencode file, something like this:
You get the idea. There was a point where i had it working properly, except that was before I realized I had to take the CSV and do the ux2dos on it, but once I threw in hte ux2dos bit it stopped working. Any ideas? I've tried just about every variation I could find in the forums, but there must be something I'm not understanding here.
I appreciate your help, and if you're in the kansas city area I'll meet you at a bar and buy you a beer sometime lol.