Envoyé par
ybalauze
bonjour,
Je souhaiterais savoir s'il existe une commande (type grep) avec une option particulière peut-être, afin de rechercher une chaine exacte dans une liste
Possibilités :
1._ Sur le mot ( word ) :
grep -E -
w toto fichier.txt
-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 pre-
ceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-con-
stituent characters are letters, digits, and the underscore.
ou autre syntaxe, chaîne commençant par toto et finissant par toto (équivaut à l'option
-w)
grep -E '
\<toto
\>' fichier.txt
2._ Sur une chaîne commençant par toto....
grep -E '\<toto' fichier.txt
3._ Sur une chaîne finissant par ....toto
grep -E 'toto\>' fichier.txt
Exemple
fichier.txt :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| toto
toto,
toto:
toto1
1toto
2toto2
toto
toto
toto
.toto.
-toto-
<tab>toto
<tab>toto
toto
blabla.toto
toto.blabla
blabla.toto.blabla |
$ grep -E '\<toto' toto.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| toto
toto,
toto:
toto1
toto
toto
toto
.toto.
-toto-
toto
toto
toto
blabla.toto
toto.blabla
blabla.toto.blabla |
Partager