I would like to replace /n with ',' and after replace remove last semicolon then put a open brace in starting and closing brace in end of line. See below example:
input:
1234
3455
24334
234
output:
('1234,'3455',24334','234')
Thanks
I would like to replace /n with ',' and after replace remove last semicolon then put a open brace in starting and closing brace in end of line. See below example:
input:
1234
3455
24334
234
output:
('1234,'3455',24334','234')
Thanks
Hi
$ cat file
1234
3455
24334
234
$ awk '$0=q $0 q' q="'" file | paste -s -d, | sed 's/.*/(&)/'
('1234','3455','24334','234')
Guru
Like this?
paste -sd, infile|sed "s/,/','/g;s/^/(/;s/\$/)/"
Or a bit shorter (after looking at Guru's solution :)):
paste -sd, infile|sed "s/,/','/g;s/.*/(&)/"
awk -v r="'" 'BEGIN{printf "( "}{$0=r $0 r;if(NR!=1){printf ","};printf "%s", $0}END{print " )"}' filename