Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
single quote usage in awk
single quote using in awk
###### Using Single QUote in awk script
function ltrim_single_quote(s) { return sub(/^\047+/, "", s); return s}
function rtrim_single_quote(s) { return sub(/'\047+$/, "", s); return s}
function trim_single_quote(s) { return ltrim_single_quote(rtrim_single_quote(s)) }
* [reference 1](http://www.gnu.org/software/gawk/manual/html_node/Quoting.html)
###### Using Single Quote in command line
This command will print "'demo'":
* Using variable
`echo 'demo' | awk -v q=\' '{printf "%s%s%s\n", q, $0, q}'`
* Using hex or octal representation of the ascii character
`echo 'demo' | awk '{printf "\x27%s\x27\n", $0}`
`echo 'demo' | awk '{printf "\047%s\047\n", $0}`
* [reference 1](http://www.techsupportforum.com/forums/f64/using-the-single-quote-character-in-an-awk-print-statement-373710.html)
* [regerence 2](http://stackoverflow.com/a/23118995/1889327)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.