Can I grep the telnet command?

I have a telnet command that prints hundreds of lines of output. Can I output grep?

+4
source share
3 answers

Use the script command. If you run the 'script' before running telnet, all the text that is written to the terminal is also written to / file / path / filename. You will need to do "exit" or Ctrl-D to actually write the file, or you can save the file check.

Finally grep in the file using the file name | grep "search text"

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

Using a script command

script /tmp/myscript.txt 

then all the commands that you run in the terminal and the output will be in this file. use ctrl + D when you are finished, which will be written to the file.

Make grep in this file.

 cat /tmp/myscript.txt | grep "textToSearch" 
+11
source

Use the tee command to redirect content to a file:

 telnet google.com 80 | tee outfile 

Then grep file

+6
source

To grep output from a network connection, you can use the Bash shell instead of telnet , for example:

 exec {stream}<>/dev/tcp/example.com/80 printf "GET / HTTP/1.1\nHost: example.com\nConnection: close\n\n" >&${stream} grep Example <&${stream} 
-1
source

All Articles