Linux command for exporting output to a csv file in separated columns

I am wondering when using Linux command line, how can I output a result i grep to a CSV file in different columns.

Here are the columns i grep from 'last' command

enter image description here

The final format, I would like to achieve, right now I have to import the data manually from a txt file is the following:

enter image description here


You only need to replace the tab with comas and set the output to a csv file:

grep "hello    world" | tr "\\t" "," > file.csv

the text in grep can be a cat to your file to get all the content

I'm not sure if it is a tab or only a white space on your output, in case there is a white space:

grep "hello world" | tr " " "," > file.csv

Another way is to sed the output with

df -h | sed -E 's/ +/,/g'

In my case I needed to grab the df output.

The Plus-sign is a multiplicator (one or more of in this case), and the substitution is ,. The -E must be used, because we want to use regex.