Script that gathers specific values from files and puts it into HTML to send e-mail

Hi All,

Sorry for long topic here.

So the drill goes like that, I need a script which gathers different values from different files/locations.

A_CT=`cat a.dat | awk -F'|' '{print $1}' >> report.txt`
B_CT=`cat b.dat | awk -F'|' '{print $3}' >> report.txt`
C_CT=`cat c.dat | awk -F'|' '{print $5}' >> report.txt`

( this is how im planning to do for taking information i need, there will be 39 files like this, and the columns i print may vary, so im guessing im gonna have to make it this all the way down )

Then lets say i have body.html file where lays only the body of the table, where i have put collumn names and formated the table how i want. I dont have the code, but it's simple. So what i need is to take those values $A_CT, $B_CT , $C_CT and substitute everyhting i need in html body. As this substitution goes, it doesnt have to impact the original body.html file but put a copy of lets say email_out_2015.08.31.html for sending email.

Plus i will have some recipients to send this mail, what's your suggestion do i put recipients straight into script, like:
recipients=one@one.com two@two.com ... etc..
or should i have seperate file name recipients.txt ?
--------------------------------------------------------

The problems I've met already.
If i put the needed values into values.dat file, and try putting them with this line :

awk 'BEGIN {print "<table>"}
  {print "<tr>"; for(i = 1; i <= NF; i++) print "<td>" $i "</td>"; print "</tr>"}
  END {print "</table>"}' report.txt > report.html

I dont get what i need, i dont get collumn names depending of the filename value has been taken off or, simple html configuration.

So guys any suggestions to do it in simple yet better way, than I'm doing this, cause I know this is an easy one, but since im the starter with UNIX I need your help guys. Any suggestions?

Thanks in advance ;}

Please use code tags as required by forum rules!

I only get half of what you describe, but from that I feel and see that your approach is way too complex. From what I understand, almost everything you request can be done in one (or a few) awk scripts and mayhap some control files.

Please post at least a handful of input files and a detailed description of what goes where on which condition, code and data in code tags.

1 Like

Sorry about not using code tags, and thanks for editing it for me.
Ok, hopefully it will help you to understand me better.
I have 39 files in different locations, and I need to take only a certain column from each of the file. File would look like:

$cat example.dat
3102|3262|6363|7574|2634|5353

Let's say I will take column 5 and put it into report.txt file. Keep in mind that i have �39 files .dat files that I need to gather information from. So Im doing it like this:

A_CT=`cat delta.dat | awk -F'|' '{print $5}' >> report.txt`
B_CT=`cat audit.dat | awk -F'|' '{print $5}' >> report.txt`
C_CT=`cat extract.dat | awk -F'|' '{print $5}' >> report.txt`

All of the values I need will go to

report.txt

.
And then I need all the values to go to HTML table which will be sent by e-mail from UNIX.
I'm stuck at putting values into HTML with the column names I need. For example, I need 3 columns which will contain 3 data types : delta, audit, extract. And one row with the file name's I've gathered information from.

                  audit           delta             extract
filename      1111           1111              1111
filename2    1111           1111              1111
filename3    1111           1111              1111

And this as HTML, will be sent by email. I hope I made it more clearly this time :wink:

Still not clear. I can't see where "filename?" is coming from, where "1111" is coming from, and how those values should be distributed into the target table. The structure and usage of "report.txt" I can't infer.
Let's step back and tackle each subtask by itself.
1) you want to extract certain fieds from certain files. Post directory structure, files and field numbers.
2) Do you want to limit the number of lines from each file that go to report.txt?
3) you want to combine those fields into some sort of table. Post what goes where, and where it comes from.
4) Where is values.dat (in post#1) used?

1 Like

Ok,
Filename.dat comes from where I take my values,lets say its /data/user/database/ .
Value 1111 is random value which I will get from filename.dat with this command:

A_CT=`cat delta.dat | awk -F'|' '{print $5}' >> report.txt`

(delta.dat is the same as filename.dat, and column 5 would represent 1111 value)

1) Yes. But it will be a lot to post, lets say I have all files in /data/user/database/ and I will take field 5.
2) I can't understand the question correctly.

3) Ok, so we have filename.dat I will will take one column and put it into first row, then im taking second file which goes into same row, but different column and so on. Next row start's when I'm extracting values from another files.
(It still maybe little unclear, thing is that one file will have lets say 3 columns i need, the 4th column will be populated from different file.)

File structure you could see at post above

$cat filename.dat
3102|3262|6363|7574|2634|5353