Sathish Kumar Palani
Sathish Kumar Palani

Reputation: 11

I want my bash script output in html format?

I am parsing the csv file using bash script, my output will be in tabular form with number of rows and coloums, so when i redirect my output to text file alignment mismatch and look so messy.

Can anyone guide me how to redirect my output to html format or suggest me with anyother alternative way.

Thanks in advance

Upvotes: 1

Views: 5117

Answers (3)

Fritz G. Mehner
Fritz G. Mehner

Reputation: 17198

A simple solution wold use column(1):

column -t -s, <( echo "head1,head2,head3,head4"; cat csv.dat )

with a result like this one:

head1  head2     head3   head4
aaaa   33333     bbb     123
aaa    333333    bbbx    123
aa     3333333   bbbxx   123
a      33333333  bbbxxx  123

Upvotes: 1

Dennis Williamson
Dennis Williamson

Reputation: 360365

If you don't really need the output in HTML, but you're having trouble with column alignment using tabs, you can get good column alignment with printf.

By the way, it would help if your question included some sample input, the script that you're using to parse and output it and some sample output.

Here is a simple demonstration of printf:

$ cat file
example text,123,word,23.12
more text,1004,long sequence of words,1.1
text,1,a,1000.42

$ cat script
#!/bin/bash
headformat='%-*s%-*s%*s%*s\n'
format='%-*s%-*s%*d%*.*f\n'
modwidth=16; descwidth=24; qtywidth=6; pricewidth=10
printf "$headformat" "$modwidth" Model "$descwidth" Desc. "$qtywidth" Qty "$pricewidth" Price
while IFS=, read model quantity description price
do
    printf "$format" "$modwidth" "$model" "$descwidth" "$description" "$qtywidth" "$quantity" "$pricewidth" 2 "$price"
done < file

$ ./script
Model           Desc.                      Qty     Price
example text    word                       123     23.12
more text       long sequence of words    1004      1.10
text            a                            1   1000.42

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

Write it out in TSV, then have a XSLT stylesheet convert it from TSV to XHTML. You can use $'\t' in bash to produce a tab character.

Upvotes: 1

Related Questions