I have data as
abc,defg,hijklm,op,qrs,tuv
I want this data to be converted to
'abc','defg','hijklm','op','qrs','tuv'
I want to do in linux. I used "sed". I have been looking all over internet,but didnot come across a solution. Please help me.
Using
awk
gsub
function. Here all the ",
" are replaced by','
and start and the end of the line is replaced by "'
".Add a single quote at start (
^
) & end ($
), and replace comma by quote-comma-quote (like you did) using sed with 3 expressions (using-e
option to specify them):(also: protect single quotes with double quotes)
results in:
in
awk
(maybe a little clumsy), generally better since field parsing is handled natively byawk
:(print all fields plus comma except for the last one)
another
awk