13

"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 \..?

1 Answer 1

17

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .