-2

Can any one please help me I need a output of "192.168.1.1#53" by using these 'grep' 'sed' and 'cut' command mandatory in linux bash scipting in given below text.

;; Query time: 29 msec ;; SERVER: 192.168.1.1#53(192.168.1.1) ;; WHEN: Sat Sep 19 12:20:54 BST 2020

2 Answers2

0

Assuming that each element of the string is separated by a single space:

grep Query | cut -f8 -d" " | cut -f1 -d"("
0

Try this:

grep -Eo [0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\#[0-9]+ <filename>

The -E makes grep work like egrep

The -o returns only the matching parts