I explain: I get a response string from a switch console. This is fine and it works. A command is executed that returns a table like this:
SwitchPrueba#show port-security
Secure Port MaxSecureAddr CurrentAddr SecurityViolation SecurityAction
(Count) (Count) (Count)
---------------------------------------------------------------------------
Fa0/1 2 1 0 Restrict
Fa0/2 1 0 0 Restrict
Fa0/3 1 0 **8** Restrict
Fa0/4 1 0 0 Restrict
Fa0/5 1 0 0 Restrict
Fa0/6 1 0 0 Restrict
Fa0/7 1 0 0 Restrict
Fa0/8 1 0 0 Restrict
Fa0/9 1 0 0 Restrict
Fa0/10 1 0 0 Restrict
Fa0/11 1 0 0 Restrict
Fa0/12 1 0 0 Restrict
Fa0/13 1 1 0 Restrict
Fa0/14 1 1 0 Restrict
Fa0/15 1 0 0 Restrict
Fa0/16 1 0 0 Restrict
Fa0/17 1 0 0 Restrict
Fa0/18 1 1 0 Restrict
Fa0/19 1 0 0 Restrict
Fa0/20 1 0 0 Restrict
SwitchPrueba#exit
Now comes the problem. I need to execute another command that is executed depending on the SecurityViolation column where the command to execute is when the values of that column are greater than 0. So the command would be something like this:
clear port-security dynamic interface Fa0/3
since it is the only one greater than 0
All that table I receive as a string. And I really don't know how to test to try to get line by line or column by column.
I do not put code because I do not have. It would practically be something like this:
String respuesta = "SwitchPrueba#show port-security
Secure Port MaxSecureAddr CurrentAddr SecurityViolation SecurityAction
(Count) (Count) (Count)
---------------------------------------------------------------------------
Fa0/1 2 1 0 Restrict
Fa0/2 1 0 0 Restrict
Fa0/3 1 0 **8** Restrict
Fa0/4 1 0 0 Restrict
Fa0/5 1 0 0 Restrict
Fa0/6 1 0 0 Restrict
Fa0/7 1 0 0 Restrict
Fa0/8 1 0 0 Restrict
Fa0/9 1 0 0 Restrict
Fa0/10 1 0 0 Restrict
Fa0/11 1 0 0 Restrict
Fa0/12 1 0 0 Restrict
Fa0/13 1 1 0 Restrict
Fa0/14 1 1 0 Restrict
Fa0/15 1 0 0 Restrict
Fa0/16 1 0 0 Restrict
Fa0/17 1 0 0 Restrict
Fa0/18 1 1 0 Restrict
Fa0/19 1 0 0 Restrict
Fa0/20 1 0 0 Restrict
SwitchPrueba#exit"
Considering what you expose, what could be done is to take the execution output of the first command and analyze it from java. Below is an example that works well with your case, that is, it prints the interface whose security violation is greater than zero. In each line of code I put what I do. This is an indicative example (so you can see the main idea of data analysis), it will be up to you to adapt/improve it according to your needs. I base myself on the example you put as output. To invoke a command from a java program, use the line
In the exec you have to put the command you want to execute, in my case the example jar (port-security.jar) returns your output on the screen emulating the process you do. You have to adapt it to yours.
This is the complete example considering only the analysis of the information
The screen output is (which is the data that was trying to get).
Greetings and I hope it will be useful to you.