The Computer Oracle

How to use awk separator of single quote?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Horror Game Menu Looping

--

Chapters
00:00 How To Use Awk Separator Of Single Quote?
00:36 Accepted Answer Score 16
01:10 Thank you

--

Full question
https://superuser.com/questions/470846/h...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#unix #awk #escapecharacters

#avk47



ACCEPTED ANSWER

Score 16


To insert a single quote character in a single-quoted string, end the current string, write "'" or \' and begin the string again.

In your example, that's

awk 'BEGIN{FS="'"'"'"}{print $2}'

or

awk 'BEGIN{FS="'\''"}{print $2}'

However, using the -F switch to specify the field separator will result in more legible code:

awk -F\' '{print $2}'