Символ \
10.8.5 Символ обратной косой черты \
В некоторых случаях вам может понадобиться сопоставить символ, который является специальным символом регулярного выражения. Например, рассмотрим следующее:
sysadmin@localhost:~/Documents$ cat newhome.txt
Thanks for purchasing your new home!!
**Warning** it may be haunted.
There are three bathrooms.
**Beware** of the ghost in the bedroom.
The kitchen is open for entertaining.
**Caution** the spirits don't like guests.
Good luck!!!
sysadmin@localhost:~/Documents$ grep 're*' newhome.txt
Thanks for purchasing your new home!!
**Warning** it may be haunted.
There are three bathrooms.
**Beware** of the ghost in the bedroom.
The kitchen is open for entertaining.
**Caution** the spirits don't like guests.
В выводе grep
приведенной выше команды поиск re*
соответствует каждой строке, содержащей r
ноль или более букв, за которыми следует e
.
Чтобы найти фактический *
символ звездочки, поместите \
символ обратной косой черты перед символом звездочки *
:
sysadmin@localhost:~/Documents$ grep 're\*' newhome.txt
**Beware** of the ghost in the bedroom.
Last updated