1

I have a file which looks like this:

ID avedebv debv2019 ebv2018 gebv2018 number avecvlean 7063993 1.06109 0.5325 0.7420 1.5084 206 66.5962 7076247 1.67947 2.1066 2.8630 3.0629 460 67.6856 7076881 -0.236859 -2.6794 0.8820 1.9994 282 66.1557 7126254 -0.409945 -2.2293 0.5860 1.2695 133 66.0323 7178892 0.464492 -0.0859 1.2640 1.3655 327 66.3985 7179256 1.33735 2.2111 1.4730 1.0873 48 67.9671 7247048 0.875797 0.8434 1.5680 2.3221 86 67.8639 7247721 2.44818 3.8560 2.2590 3.7478 306 69.2416 7271572 2.54853 4.1963 2.5310 2.4604 268 68.9649 7271958 1.48163 2.1094 2.6480 2.4154 396 67.8631 7310883 2.07762 2.6693 0.5610 0.8019 164 69.8769 7339810 1.93014 2.7640 2.4130 2.0771 112 70.453 7362729 1.79878 2.5744 1.5900 2.6763 247 69.8597 7383443 1.20869 1.0631 0.6140 0.7587 229 69.4386 7384385 1.95598 1.2635 3.1930 2.1413 32 71.9848 7385021 3.01675 3.7090 1.3690 1.4910 22 71.2533 7385509 0.686986 -0.1679 0.1500 0.2087 81 69.8795 7392631 2.07126 4.0996 0.8400 1.6370 103 70.6173 

I want to change its format into an Excel file, so I can work on this data in Excel. How can I convert it with Linux?

2
  • 3
    You can simply open the file with excel, select the Data tab, select Text to Columns, ensure the Delimited radio button is selected and press next, set the Delimeters to Space, and press Finish. Then save as excel workbook Commented May 24, 2019 at 15:18
  • If doing this manually is an option, then maybe use libreoffice (calc) to import the file into columns then save in Excel format. Commented May 24, 2019 at 15:19

2 Answers 2

5

Replace each space with a comma to turn it into a Comma Separated Value file, and save it with a XLS suffix; then you can read it in to Excel (which will read the comma separated value data and turn it into XLS format automagically), work with it, and save it. Here's a one liner which uses sed to do the search-and-replace, then saves the data to CSV format with the XLS suffix, and Bob's yer uncle.

sed -e 's/\s\+/,/g' filename > filename.xls 
2
  • 1
    yes, or tr ' ' , <filename > filename.xls Commented May 24, 2019 at 20:22
  • ss64.com/bash/tr.html is a man page for tr Commented May 24, 2019 at 20:27
0

Tried with below command and it worked fine

command

awk '{gsub(" ",",",$0);print $0}' filename| sed "s/,$//g" >file.xls 

output

awk '{gsub(" ",",",$0);print $0}' filename| sed "s/,$//g" ID,avedebv,debv2019,ebv2018,gebv2018,number,avecvlean 7063993,1.06109,0.5325,0.7420,1.5084,206,66.5962 7076247,1.67947,2.1066,2.8630,3.0629,460,67.6856 7076881,-0.236859,-2.6794,0.8820,1.9994,282,66.1557 7126254,-0.409945,-2.2293,0.5860,1.2695,133,66.0323 7178892,0.464492,-0.0859,1.2640,1.3655,327,66.3985 7179256,1.33735,2.2111,1.4730,1.0873,48,67.9671 7247048,0.875797,0.8434,1.5680,2.3221,86,67.8639 7247721,2.44818,3.8560,2.2590,3.7478,306,69.2416 7271572,2.54853,4.1963,2.5310,2.4604,268,68.9649 7271958,1.48163,2.1094,2.6480,2.4154,396,67.8631 7310883,2.07762,2.6693,0.5610,0.8019,164,69.8769 7339810,1.93014,2.7640,2.4130,2.0771,112,70.453 7362729,1.79878,2.5744,1.5900,2.6763,247,69.8597 7383443,1.20869,1.0631,0.6140,0.7587,229,69.4386 7384385,1.95598,1.2635,3.1930,2.1413,32,71.9848 7385021,3.01675,3.7090,1.3690,1.4910,22,71.2533 7385509,0.686986,-0.1679,0.1500,0.2087,81,69.8795 7392631,2.07126,4.0996,0.8400,1.6370,103,70.6173 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.