O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Converting text to HTML table

In this example, we use FS – the field separator to set it to the desired delimiter for splitting the line of files into fields. Then, we create the heading of the HTML table in the BEGIN block by fetching the elements of the first record, by checking whether NR==1. Then, the body of the table is created using NR >1, until the last line of the file is read. The following is a sample file named table.txt used here to illustrate the text-to-HTML table conversion, as follows:

$ vi table.txtNAME:ENGLISH:MATHS:SOCIAL SCIENCE:MUSICSanjay:70:80:65:95Hitesh:55:72:82:64Rahul:80:83:65:70Dhirendra:81:82:83:84
$ vi array2html.awkBEGIN {    FS =":";    printf  "%s%s%s",         "<TABLE cellpadding=\"1pt\" BORDER=\"2pt\" ", "CELLSPACING=\"0pt\" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required