-2

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?

Michael Jaros
  • 4,586
  • 1
  • 22
  • 39
Harry shah
  • 387
  • 1
  • 3
  • 9
  • possible duplicate of [Can grep show only words that match search pattern?](http://stackoverflow.com/questions/1546711/can-grep-show-only-words-that-match-search-pattern) – Michael Jaros Mar 07 '15 at 23:50

3 Answers3

0

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.

fzzfzzfzz
  • 1,248
  • 1
  • 12
  • 22
0

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.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

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
Jotne
  • 40,548
  • 12
  • 51
  • 55