0

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.

1

1 Answer 1

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

4
  • thanks, that works .i want to export this into a excel sheet.how can i do that?
    – noob_coder
    Aug 14, 2017 at 6:10
  • Just like you did in your question. Just redirect the output with > to a file. Aug 14, 2017 at 6:12
  • i just edited the question with a sample excel sheet with proper formatting that i need..is something like this possible?
    – noob_coder
    Aug 14, 2017 at 6:18
  • What is the difference? One empty line after the header? Add a \n to the echopart: echo -e "header1\theader2\n" ... Aug 14, 2017 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.