It is a simple problem. I have a csv file with multiple columns I would like to extract 3 columns and save the output to a text file.
sample of my dataset:
page_id     post_name   link        post_type       likes_count
5550296508  Ben Carson  www.cnn.com shared_story    192583
5830242058  John Smith  www.abc.com news_story      467
9485676544  Sara John   www.msc.com shared_story    462
I would like to select three columns and save them to a text file with a comma seperator.The desired output: (or any similar format that shows the columns in a neat way. it doesn't have to be exactly like this format)
"page_id","post_name","post_type"
"5550296508","Ben Carson","shared_story"
"5830242058","John Smith", "news_story" 
"9485676544", "Sara John",  "shared_story" 
I tried to use awk:
awk -F',' '{print $1,$2,$4}' Data.csv > output.txt
It returns this output with a blank space between the columns, I would like to replace the blank space with a comma:
page_id     post_name   post_type 
5550296508  Ben Carson  shared_story    
5830242058  John Smith  news_story   
9485676544  Sara John   shared_story 
I tried printf but I am not sure I am using the correct string because it doesn't return the output I want.
awk '{printf "%s,%s,%s", $1,$2,$4}' Data.csv > output.txt
using sed. This only replaces the first blank with a comma.
awk -F',' '{print $2,$5,$10}' Data.csv | sed 's/ /,/' > output.txt

