First of all, less
is just a pager, it is a tool that lets you read files. What you're doing is exactly the same as copying input_file to out_put.csv (cp input_file out_put.csv
). You're not changing the content in any way.
So, to read it as a spreadsheet using, for example libreoffice
, you would need to open your spreadsheet application, then open your input_file
and use space as the column separator:
Now, if you really want to convert your file to comma separated values format (.csv
), you would need to add commas. This command will replace all spaces with commas on each of your lines and save the output as output.csv
:
sed 's/ */,/g' input_file > output.csv
The command above is sed
and here I am using its substitution operator. The general format is s/pattern/replacement/
which will replace pattern
with replacement
. The g
at the end makes it replace all occurrences of the pattern on each line, without it, it would only replace the first. The pattern I gave it was
(a space) followed by 0 or more (that's what *
means) spaces (*
) and I told it to replace with ,
. This basically means "replace any occurrences of one or more spaces with a comma".
less input_file