Есть файл test.dat:
Код:
1st_test
test-2nd
test
нужно найти в нем строку, содержащую отдельно стоящее слово test.
Особенность в том, что в строке test-2nd после искомой test стоит "минус", т.е. разделитель.
Неудачные попытки:
1.
Код:
:~$ grep -w test test.dat
test-2nd
test
:~$ man grep
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent char acter. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.
2.
Код:
:~$ grep "\<test\>" test.dat
test-2nd
test
:~$ man grep
REGULAR EXPRESSIONS
The symbols \< and \> respectively match the empty string at the beginning and end of a word.
Социальные закладки