I think you don't just want the word "team", but have it in between hyphens and spaces as an indicator. In that case, a regular expression would be: ^[-]+[[:space:]]team[[:space:]][-]+$
Thirsty
In the command it sedwould be of the form
$ sed -nr '/^[-]+[[:space:]]equipo[[:space:]][-]+$/p' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
Where the parameter -nsuppresses the output of the file before the pattern is found, and the parameter -renables regular expressions.
Although you can also do the same with other options like egrep, grepor awksomething like that.
egrep and grep
$ egrep '^[-]+[[:space:]]equipo[[:space:]][-]+$' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
EITHER
$ grep -E '^[-]+[[:space:]]equipo[[:space:]][-]+$' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
-qHere you can make use of the parameter grepif the only thing you want is "to know if it exists" not only "to know if it exists and also print it on the screen". This is because the parameter -qdoes not generate an output, but rather an exit status of 0 —if the pattern is found or even if there is an error— or different from 0 —if the pattern is not found. You can check this in grep(1). Example:
$ grep -E '^[-]+[[:space:]]equipo[[:space:]][-]+$' archivo.txt -q && echo Si existe || echo no existe
Si existe
with awk
$ awk '/^[-]+[[:space:]]equipo[[:space:]][-]+$/' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
Where, if the pattern is found, the default action will be taken, awkwhich is to print the entire record.
About the regular expression.
The explanation of that regular expression is that "^[-]+" expects the pattern to start (^) with a repetition of more than one "-" character ([-]+), then with a space ([[:space :]]) and then continue the word "team" and then repeat in the same way ([[:space:]] and [-]+) but end with that pattern ($)
Now, if you only want the word "team" to be there, no matter what comes before or after, you can remove the meta characters and leave only the commands with the word team.
I think you don't just want the word "team", but have it in between hyphens and spaces as an indicator. In that case, a regular expression would be: ^[-]+[[:space:]]team[[:space:]][-]+$
Thirsty
In the command it
sed
would be of the formWhere the parameter
-n
suppresses the output of the file before the pattern is found, and the parameter-r
enables regular expressions.Although you can also do the same with other options like
egrep
,grep
orawk
something like that.egrep and grep
EITHER
-q
Here you can make use of the parametergrep
if the only thing you want is "to know if it exists" not only "to know if it exists and also print it on the screen". This is because the parameter-q
does not generate an output, but rather an exit status of 0 —if the pattern is found or even if there is an error— or different from 0 —if the pattern is not found. You can check this ingrep(1)
. Example:with awk
Where, if the pattern is found, the default action will be taken,
awk
which is to print the entire record.About the regular expression.
The explanation of that regular expression is that "^[-]+" expects the pattern to start (^) with a repetition of more than one "-" character ([-]+), then with a space ([[:space :]]) and then continue the word "team" and then repeat in the same way ([[:space:]] and [-]+) but end with that pattern ($)
Now, if you only want the word "team" to be there, no matter what comes before or after, you can remove the meta characters and leave only the commands with the word team.