panda panda -3 years ago 124
Perl Question

How to convert a text file into excel in bash or perl

sample excel sheetI have a text file that has some data such as

aaaa:1.0
bbbb:1.1
cccc:1.3


I want to covert this into an excel sheet using bash/perl
The desired output is something like this

header1 header2
aaaa 1.0
bbbb 1.1
cccc 1.3


what i have tried so far is

(echo "header1;header2" ; cat a.txt) | sed 's/:/\t/g' > a.csv


but this does not seem to work.
also i want to export this text file into an excel sheet.

Answer Source
$ echo -e "header1\theader2"; cat file | tr : '\t'    # > file.csv
header1 header2
aaaa    1.0
bbbb    1.1
cccc    1.3

or:

$ cat <(echo  "header1:header2") file | tr : '\t'     # > file.csv
header1 header2
aaaa    1.0
bbbb    1.1
cccc    1.3

Uncomment the > file.csv to actually write to a file.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download