suhas savkoor
suhas savkoor

Reputation: 133

Format text output of script to html

I have the following shell script:

#!/bin/bash
f='/tmp/cases.txt' 
[ -s "$f" ] || printf '%s   |\t%s   |\t%s                    |\n' '#' 'Case Number' 'Date Opened' > "$f"
n=$(cat /tmp/cases.txt | grep 17* |wc -l)
read -p "Enter your SR number: " SR
printf '%d   |\t%d   |\t%s   |\n' "$n" "$SR" "$(date)" >> "$f"
echo -e "-------------------------------------------------------" >> "$f"

This outputs:

#   |   Case Number   | Date Opened                    |
0   |   17416230803   | Wed Mar 29 02:26:24 IST 2017   |
-------------------------------------------------------
1   |   17416230802   | Wed Mar 29 02:32:28 IST 2017   |
-------------------------------------------------------
2   |   17416230801   | Wed Mar 29 02:32:33 IST 2017   |
-------------------------------------------------------

Now, I want to format this output to a html file. The same way how I see in this text output. And if this could generate a link, which I could paste in my browser that would even more cool. I have barely any idea on html so it would be a lot helpful.

Thanks.

Upvotes: 0

Views: 566

Answers (1)

shaochuancs
shaochuancs

Reputation: 16246

You can use the ansi2html.sh script to generate html file from console output. For example, you can generate the output of ls -l as html by:

ls -l | ./ansi2html.sh > ls.html

Please note you can define the generated file path yourself, which means the "link" is up to you.

p.s. In MacOS, you need to install gawk and gnu-sed before running ansi2html.sh

Upvotes: 1

Related Questions