I have the following file in centos:
I want the program to check if there is "equipment" with a regular expression like it would be with the sed command ???
I think you do not just want the word "team", but that you are in the middle of scripts and spaces as an indicator. In that case, a regular expression would be: ^ [-] + [[: space:]] computer [[: space:]] [-] + $
In the sed
command, it would be in the form
$ sed -nr '/^[-]+[[:space:]]equipo[[:space:]][-]+$/p' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
Where the parameter -n
suppresses the output of the file before finding the pattern, and the parameter -r
enables the regular expressions.
Although you can also do the same with other options like egrep
, grep
or awk
with something of the style.
$ egrep '^[-]+[[:space:]]equipo[[:space:]][-]+$' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
O
$ grep -E '^[-]+[[:space:]]equipo[[:space:]][-]+$' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
$ awk '/^[-]+[[:space:]]equipo[[:space:]][-]+$/{print $0}' archivo
---------------------- equipo -----------------------
---------------------- equipo -----------------------
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 it in the same way ([[: space:]] and [-] +) but end with that pattern ($)
Now, if you just want the word "team" to be there, no matter what you have before or after, you can remove the meta characters and leave only the commands with the word team.
$ sed '/equipo/p' archivo
$ grep 'equipo' archivo
$ awk '/equipo/{print $0}' archivo