1

I don't know HTML (HORRIBLY EMBARRASSED but didn't ever have the need to). I am pretty perspicacious when it comes to UNIX however I am horribly confused with this assignment I have. I know what I need to do but am having the hardest time ever getting started.

I have the following files in my hwk12 directory:

  • roster.html
  • roster.txt
  • sample.html
  • sample.txt

The following is the content of the roster.html file:

<html>
<body>
<table border=2>
<tr><th>Name</th><th>Username</th><th>Email</th></tr>
  <tr>
    <td>Nikhil Banerjee</td>
    <td>nbanerje</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Jeff Nazarian</td>
    <td>jnazaria</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Anna Melzer</td>
    <td>amelzer</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Jose Garcia</td>
    <td>jgarcia</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Jillian Testa</td>
    <td>jtesta</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Clayton Lengelzigich</td>
    <td>clengelz</td>
    <td><a href="mailto:[email protected]">clayton.lengel-  
[email protected]</a></td>               
  </tr>
  <tr>
    <td>Ashley Bennett</td>
    <td>abennett</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Ann Frost</td>
    <td>afrost</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Timothy Whipple</td>
    <td>twhipple</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Wei Shen</td>
    <td>wshen</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Cari Mahon</td>
    <td>cmahon</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Alberto Salas</td>
    <td>asalas</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Dorothy Haskett</td>
    <td>dhaskett</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Criss Bradbury</td>
    <td>cbradbur</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Steve Ellermann</td>
    <td>sellerma</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Zewdie Bekele</td>
    <td>zbekele</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Frederic Diziere</td>
    <td>fdiziere</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Matt Bowes</td>
    <td>mbowes</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Jasen Meece</td>
    <td>jmeece</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Aaron Carpenter</td>
    <td>acarpent</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Binqin Xi</td>
    <td>bxi</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Yinting Chan</td>
    <td>ychan</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Michael Evans</td>
    <td>mevans</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Herman Beringer</td>
    <td>hberinge</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Andrew Jolley</td>
    <td>ajolley</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Michael Raby</td>
    <td>mraby</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Hajar Alaoui</td>
    <td>halaoui</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Anne Lemar</td>
    <td>alemar</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Russell Crotts</td>
    <td>rcrotts</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Dan Mazzola</td>
    <td>dmazzola</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Bill Boyton</td>
    <td>bboyton</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
</table>
</body>
</html>

The following is the content of the roster.txt file:

Whipple Timothy [email protected] Shen    Wei     [email protected]
Mahon   Cari    [email protected] Salas   Alberto [email protected]
Haskett Dorothy [email protected] Bradbury        Criss  
[email protected] Ellermann       Steve  
[email protected] Bekele  Zewdie  [email protected] Diziere Frederic 
[email protected] Bowes   Matt    [email protected] Meece   Jasen  
[email protected]  Carpenter       Aaron   [email protected]
Xi      Binqin  [email protected] Chan    Yinting [email protected]
Evans   Michael [email protected] Beringer        Herman 
[email protected] Jolley  Andrew  [email protected] Raby    Michael
[email protected] Alaoui  Hajar   [email protected] Lemar   Anne   
[email protected] Crotts  Russell [email protected] Mazzola Dan 
[email protected] Boyton  Bill    [email protected]

The following is the content of the sample.html file:

<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:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Hajar Alaoui</td>
    <td>halaoui</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Anne Lemar</td>
    <td>alemar</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Russell Crotts</td>
    <td>rcrotts</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Dan Mazzola</td>
    <td>dmazzola</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
  <tr>
    <td>Bill Boyton</td>
    <td>bboyton</td>
    <td><a href="mailto:[email protected]">[email protected]</a></td>
  </tr>
</table>
</body>
</html>

The following is the content of the sample.txt file:

Raby    Michael [email protected]
Alaoui  Hajar   [email protected]
Lemar   Anne    [email protected]
Crotts  Russell [email protected]
Mazzola Dan     [email protected]
Boyton  Bill    [email protected]

I'm not asking for someone to do this for me because I LOVE UNIX and I want to learn it myself. Everytime I look at this HTML code I am confusing the #$$#& out of myself. I need help getting started.

The homework prompt is the following:

You are to write a nawk(1) script called ~/hwk12/mk_html.awk that converts a text file (sample.txt and roster.txt) to an html page that a web browser can read. I have given you the output in the file sample.html which is reproduced below (notice how each level of indentation is two spaces deep):

Again, I don't want someone to do this for me. Im just confused as to how data in the text file will append to the HTML table without the actual HTML code. Can someone please help me get started?

5
  • Is that really how the input file is formatted? random line breaks throughout, instead of a nice email fname lname-per line? Commented Apr 15, 2013 at 21:12
  • Im pretty sure I need to loop through the text file and awk the appropriate columns to the html code. Am I right in saying this? Commented Apr 15, 2013 at 21:13
  • @MarcB are you speaking of the roster.txt file? Commented Apr 15, 2013 at 21:14
  • @MarcB, I don't know why it got reformatted when I posted the question. There is only on name with their relevant info per row, There is know random line breaks however some names in the file are not equally spaced Commented Apr 15, 2013 at 21:17
  • I guess this is my main question: Do I append the relevant data from the text file to the html file where they need to go? Commented Apr 15, 2013 at 21:27

1 Answer 1

1

Looks like you'll need to define the necessary HTML tags within your script. The meat of the html file will be these lines:

<tr>
    <td>$first $last</td>
    <td>$username</td>
    <td><a href="mailto:$email">$email</a></td>
</tr>

These tags define a table row. You can parse the variables from the text files with awk and use them to fill in the html. The other html markup can be copy-pasted as static text into the output html file.

Edit: You can do this to grab the first and last name and print to the html file.

last = $1
first = $2
print "  <tr>"
print "    <td>" first " " last "</td>"
print "  </tr>"

You just need to expand that to get the email and username.

Sign up to request clarification or add additional context in comments.

11 Comments

This is an awk assignment, can I do this with awk?
I don't know HTML and my professor said you don't need to know it. Am I correct in saying the following?: I need to create a loop that will awk the columns and append them to the HTML file.
Sorry, I meant awk, I don't know why I said sed. Edited the above. And you don't need to know html, you just need to use that format.
Yes, in an default pattern block (leave the condition blank). You can put the header and footer html in BEGIN and END blocks.
You should look up concatenation and substrings in awk.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.