Search code examples
linuxtelnet

Can I grep telnet command output?


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


Solution

  • 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"