Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading