Reputation: 1338
I am trying to enclose each line of a file in single quotes and append ,
at the end of each line.
I have tried,
sed 's/^*$/\'&\',/g' filename
I have also tried,
sed 's/^/'/;s/$/',/' filename
both don't seem to help.Please advise.
Upvotes: 2
Views: 57
Reputation: 37454
Another in awk:
$ awk 'gsub(/^|$/,"'"'"'")' file
'line one'
'line two'
'line three'
ie. the '
is double-quoted "
'
"
and that is single-quoted '
"
'
"
'
and again double-quoted in the gsub
"
'
"
'
"
'
"
. No, I'm not kidding.
Upvotes: 0
Reputation: 18411
awk -v q="'" '{$0= q $0 q ","}1' input
'line one',
'line two',
'line three',
Using awk
: 1. Enclosing the whole line between single quotes. 2. Adding comma at the end of each line.
Upvotes: 3