Reputation:
I’m using Mac Yosemite, bash shell. I want to output single quotes in my output, and I have tried several things, without success …
awk -F, '{OFS=",";print ''$1'',$4,$6,$7}' my_list.csv
and
awk -F, '{OFS=",";print "'"$1"'",$4,$6,$7}' my_list.csv
Neither of these adds the single quotes into my output. How can I achieve this?
Upvotes: 2
Views: 2713
Reputation: 785156
You can use octal code as well:
# octal code 047 for '
awk -F, -v OFS=, '{print "\047" $1 "\047", $4, $6, $7}' my_list.csv
Upvotes: 2
Reputation: 195059
using variable is one way to go:
kent$ echo "a b c"|awk -v q="'" '$1=q$1q'
'a' b c
or you pick the escaping way:
kent$ echo "a b c"|awk '$1="'\''"$1"'\''"'
'a' b c
I prefer the 1st one.
Upvotes: 4