user192082107
user192082107

Reputation: 1367

how can i display the single quote inside awk

I have this awk statemnt and its working fine

awk '{a= a","$1}END{print a}' file.txt

I want that in my output my $1 field shoube surrounded with single quotes

how can do that

Upvotes: 1

Views: 98

Answers (1)

perreal
perreal

Reputation: 97938

One way:

awk -v q="'" '{a= a","q$1q}END{print a}' file.txt

Another way:

awk '{a= a",\x27"$1"\x27"}END{print a}' file.txt

Another way:

awk '{a= a",'"'"'"$1"'"'"'"}END{print a}' file.txt

Another:

awk '{a= a",'\''"$1"'\''"}END{print a}' file.txt

Upvotes: 1

Related Questions