Regular Expression Awk – Escaping a Single Dot with Double Backslash

awkregular expression

"effective awk programming" book has an example on Field-Splitting. here is the example:

If you want fields to be separated by a literal period
followed by any single character, use ‘FS = "\\.."’.

Why it is double backslash? shouldn’t it be \..?

Best Answer

Both string and regular expressions in awk share many of the same backslash escapes, including \\ for a single \. Since FS is a string value that is internally interpreted as a regular expression, those shared escapes have to be escaped twice. Thus \\ in a string becomes \ by the time it is interpreted as a regular expression.

Related Question