Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.