Last active
August 29, 2015 14:27
-
-
Save andyxning/d59d2d438a5f42002daa to your computer and use it in GitHub Desktop.
single quote usage in awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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