Using paste command to join with multiple character delimiter
5,560
Using sed and paste together:
$ sed "s/.*/'&'/" file | paste -sd,
'2012-12-31','2012-12-30','2012-12-29'
Related videos on Youtube
Author by
divinedragon
Updated on September 18, 2022Comments
-
divinedragon over 1 year
I have a file which gets generated based on the arguments and it has the following contents.
2012-12-31 2012-12-30 2012-12-29
Now, these are actually date partitions for hive query. So, I want to use them in my hive query where I specify each of these partitions in
WHERE
clause. Something like belowWHERE log_date IN ('2012-12-31','2012-12-30', '2012-12-29')
So, I am looking the output from
paste
as2012-12-31','2012-12-30','2012-12-29
I am using the following, but I think the
-d
parameter is a list of delimiter and not one complete delimiter.paste -sd"','" datefile
Any idea how can I do that?
-
divinedragon over 11 yearsNice. I too used something similar. I added a single delimiter with
paste
and then usedsed
to replace it with actual one.paste -sd"," datefile | sed "s/\,/'\,'/g"