Through Linux On executing a shell script I am getting a output which is separated by space. I have to convert this to a excel format. This output should be converted to a excel file which should be available in home directory. Kindly help me with this
Asked
Active
Viewed 3,929 times
1 Answers
2
Excel can import delimiter separated files ("CSV"). If the space character is exclusively used as a delimiter in the file, you can easily replace all instances of the space character in the file with something Excel is more likely to recognize, like comma, semicolon, or tab characters.
The sed
command can be used for this purpose.
Example:
$ cat ~/test.txt
data1 foo1 bar1
data2 foo2 bar2
data3 foo3 bar3
$ sed 's/ /;/g' ~/test.txt > ~/test.csv
$ cat ~/test.csv
data1;foo1;bar1
data2;foo2;bar2
data3;foo3;bar3
$
The file test.csv should be importable into Excel.
Naturally you should be able to skip a step by piping the output of your original shell script straight into the sed command instead of going via a file:
myshellscript | sed 's/ /;/g' > ~/test.csv

Mikael H
- 5,031
- 2
- 9
- 18