noob_coder
noob_coder

Reputation: 829

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.

Upvotes: 0

Views: 3052

Answers (1)

James Brown
James Brown

Reputation: 37404

$ 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.

Upvotes: 2

Related Questions