awk not printing output

I am getting this output

grep -hnr '$pattern' /path/of/file/ | awk -F '=' 'BEGIN { print "<table border='1'><tr>" } { print "<td>" $3 "</td>" } { print "</tr>" }'`;

the above code is not printing anything when awk command is added to it.
Here I’m trying to convert the file data into table format using awk command.

Example of data in the files:

name==ABC
City==Rohini
State==Delhi
Age==18
Country==India

Expected output:

<html><table border="1">
<tr><td>ABC</td></tr>
<tr><td>Rohini</td></tr>
<tr><td>Delhi</td></tr>
<tr><td>18</td></tr>
<tr><td>India</td></tr>
</table>
</html>

Currently the Output I am getting

<table border=1>
<td></td>
<td></td>
<td></td>
<td></td>
</table>

>Solution :

You can use this awk with delimiter ==:

grep -hnr "$pattern" /path/of/file/ |
awk -F '==' '
BEGIN { print "<html><table border='1'><tr>" }
{ print "<tr><td>" $2 "</td></tr>" }
END { print "</table>\n</html>" }'

<html><table border=1><tr>
<tr><td>ABC</td></tr>
<tr><td>Rohini</td></tr>
<tr><td>Delhi</td></tr>
<tr><td>18</td></tr>
<tr><td>India</td></tr>
</table>
</html>

Leave a Reply