I want to understand what the backslash represents in this command. grep "\.900983" table

I know what the command does, it searches for the 900983 value in table, I'm just not sure of the purpose of the \ or what it does.

  • Okay you gave me an idea, could it be that it cancels out the digits before the decimal point, and only searches for whatever is after the decimal point? – Katz Nov 24 '15 at 2:34
  • 2
    No. Without the backslash, the period will match any single character. With the backslash, the period will only match a period. You say in your question that the command "searches for the 900983 value." That's not exactly correct; it searches for the decimal fraction .900983 (note the leading decimal.) – Darwin von Corax Nov 24 '15 at 5:10
  • @DarwinvonCorax thanks for the explanation, I understand it now. – Katz Nov 24 '15 at 18:05
  • Glad to help. If you need (or want) to learn more about regular expressions, I recommend O'reilly's Mastering Regular Expressions by Jeremy Freidl. It's quite comprehensive, so I suggest borrowing a copy first. – Darwin von Corax Nov 24 '15 at 18:44

. is a regular expression metacharacter which matches any single character.

\ is also a regular expression metacharacter which can be used to escape any metacharacter so that it will be literally matched.

and so . matches any character, but \. matches only ..

printf %c900983\\n a . | grep -n ".900983"


...because the . regular expression metacharacter matches a literal . or an a or any other single character, but...

printf %c900983\\n a . | grep -n "\.900983"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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