I facing an issue when I use this command
"grep RTB4"
The output is:
192.168.1.1 RTB4-NODE-1
I only have to get RTB4-NODE-1
in output.
How can I do this?
I facing an issue when I use this command
"grep RTB4"
The output is:
192.168.1.1 RTB4-NODE-1
I only have to get RTB4-NODE-1
in output.
How can I do this?
Assuming by "word" you mean anything not interrupted by spaces:
grep RTB4 | tr ' ' '\n' | grep RTB4
You can add more characters to the tr
command if you need to split on other forms of whitespace.
I suspect what you really want is:
awk '$NF~/RTB4/{print $NF}' file
so it only looks for the regexp in and prints the last space-separated field on each line.
This gnu awk
(gnu due to multiple characters in RS) should do:
awk -v RS=" *" '/RTB4/'
eks:
echo "192.168.1.1 RTB4-NODE-1" | awk -v RS=" *" '/RTB4/'
RTB4-NODE-1