0

So, I have been working on my own on something for a week now and am getting nowhere. I am taking a very advance CIS class that I have done well in so far but towards the end I am working with stuff that I haven't learned yet. I should have waited a couple of semesters to talk this class because I am unprepared for what I am doing now. My main problem is not knowing HTML (I haven't ever had a reason to learn it).

Any ways I have a nawk script template that I have figured out that I need to use. It is derived from a color generator script and is the following:

#!/bin/nawk -f

#-----------------------------------------------------------------------------
#YOUR COMMENTS HERE
#-----------------------------------------------------------------------------

BEGIN {
    print "<html>"
    print "<body>"
    print "  <table border=2>"
    print "    <tr>"
    print "      <th>$first $last</th>"                ###Change this
    print "      <th>$username</th>"               ###Change this
    print "      <th>Color</th>"                    ###Change this
    print "    </tr>"
}

{
    print "    <tr>"
    print "      <td>" $1 "</td>"                   ###Change this
    print "      <td>" $2 "</td>"                   ###Change this
    print "      <td>" $3 "</td>"                   ###Change this
    print "    </tr>"
}

END {
    print "</table>"
    print "</body>"
    print "</html>"
}

As you can see on the 12th and 13th line I have added $first $last, and $username respectively. Am I doing this right. Because I don't know HTML, every time I look at it, it is confusing the !@#$ out of me.

The following is supposed to be the output:

<html>
<body>
<table border=2>
<tr><th>Name</th><th>Username</th><th>Email</th></tr>
  <tr>
    <td>Michael Raby</td>
    <td>mraby</td>
    <td><a href="mailto:mike1071@yahoo.com">mike1071@yahoo.com</a></td>
  </tr>
  <tr>
    <td>Hajar Alaoui</td>
    <td>halaoui</td>
    <td><a href="mailto:hajar6@hotmail.com">hajar6@hotmail.com</a></td>
  </tr>
  <tr>
    <td>Anne Lemar</td>
    <td>alemar</td>
    <td><a href="mailto:anne.lemar@asu.edu">anne.lemar@asu.edu</a></td>
  </tr>
  <tr>
    <td>Russell Crotts</td>
    <td>rcrotts</td>
    <td><a href="mailto:Russell.Crotts@asu.edu">Russell.Crotts@asu.edu</a></td>
  </tr>
  <tr>
    <td>Dan Mazzola</td>
    <td>dmazzola</td>
    <td><a href="mailto:dan.mazzola@sun.com">dan.mazzola@sun.com</a></td>
  </tr>
  <tr>
    <td>Bill Boyton</td>
    <td>bboyton</td>
    <td><a href="mailto:boytonb@earthlink.net">boytonb@earthlink.net</a></td>
  </tr>
</table>
</body>
</html>

The following is a sample of what the HTML table is supposed to look like:

Raby    Michael mike1071@yahoo.com
Alaoui  Hajar   hajar6@hotmail.com
Lemar   Anne    anne.lemar@asu.edu
Crotts  Russell Russell.Crotts@asu.edu
Mazzola Dan     dan.mazzola@sun.com
Boyton  Bill    boytonb@earthlink.net

Can someone PLEASE help me? I've been trying to figure out this on my own for a week now.

J.S. Orris
  • 4,653
  • 12
  • 49
  • 89
  • What does your output look like? – hd1 Apr 19 '13 at 05:28
  • I have none. Im supposed to write the following commands respectively: $ mk_html.awk sample.txt > mysample.html; diff sample.html mysample.html.....I can't even get it to output. I am very confused with what I am supposed to do. – J.S. Orris Apr 19 '13 at 05:30
  • I am aware. I don't want anyone to do it for me. I just want someone to explain it for me. I've already turned it in. I am trying to learn this so I know. I've done very well in this class so far, and I am at a standstill with this. – J.S. Orris Apr 19 '13 at 05:33
  • Well, post your solution then – hd1 Apr 19 '13 at 05:34
  • Ive added the $first $last, and $username. I just want to know if Im on the right path. I had to find the template (out of like 10) from some examples by myself. I am aware I am on the right one. – J.S. Orris Apr 19 '13 at 05:35
  • I've ran this command: mk_html.awk sample.txt > mysample.html The stdError says "ksh: mysample.html: file already exists " then I cat mysample.html and get nothing. – J.S. Orris Apr 19 '13 at 05:39
  • Try `mk_html.awk sample.txt` what comes up on standard output? – hd1 Apr 19 '13 at 05:41
  • It comes up as a longer form of HTML with data actually in it. – J.S. Orris Apr 19 '13 at 05:43
  • I see, when the script is finished, I am to append the script to mysample.html...am I correct? – J.S. Orris Apr 19 '13 at 05:45
  • 1
    It looks like you need to overwrite, not append. – hd1 Apr 19 '13 at 05:47
  • mk_html.awk sample.txt > mysample.html gives me stdError: File already exists – J.S. Orris Apr 19 '13 at 05:48
  • 1
    append is adding to the end, overwriting is obliterating whatever exists and replacing it. – hd1 Apr 19 '13 at 05:51
  • If my answer helps, you would do well to accept and vote it up – hd1 Apr 19 '13 at 05:57

1 Answers1

0

It looks like the following will do what you want:

#!/bin/nawk -f

#-----------------------------------------------------------------------------
#YOUR COMMENTS HERE
#-----------------------------------------------------------------------------

BEGIN {
    print "<html>"
    print "<body>"
    print "  <table border=2>"
    print "    <tr>"
    print "      <th>Name</th>"                          ###Change this
    print "      <th>Username</th>"                      ###Change this
    print "      <th>Email</th>"                         ###Change this
    print "    </tr>"
}

{
    print "    <tr>"
    print "      <td>" $1 "</td>"                        ###Change this
    print "      <td>" $2 "</td>"                        ###Change this
    print "      <td><a href=\"" $3 "\">" $3 "</a></td>" ###Change this
    print "    </tr>"
}

END {
    print "</table>"
    print "</body>"
    print "</html>"
}
hd1
  • 33,938
  • 5
  • 80
  • 91