Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I grep telnet command output?

Tags:

linux

telnet

I have a telnet command which prints hundreds of lines of output, Can I grep the output?

like image 778
Aks Avatar asked Dec 04 '22 02:12

Aks


2 Answers

Use the 'script' command. If you run 'script ' before running telnet, all text that gets written to the terminal also gets written to /file/path/filename. You'll have to do 'exit' or Ctrl-D to actually write to the file or you can keep a check on the file.

Finally grep on the file using filename | grep "search text"

/file/path/filename is the path where you want to store the output of telnet.

Using script command

script /tmp/myscript.txt

then all the commands you fire in terminal and the output will go in this file. use ctrl + D when you are done, which will write to the file.

Do a grep on this file.

cat /tmp/myscript.txt | grep "textToSearch"
like image 76
amitchhajer Avatar answered Dec 12 '22 09:12

amitchhajer


Use tee command to redirect the content to file:

telnet google.com 80 | tee outfile

Then grep the file

like image 27
Nasir Avatar answered Dec 12 '22 10:12

Nasir