in reply to How to grep some string(IP:port) from text file and print into txt file

Do you really want to grep your input? Grepping the input would essentially means to filter out some lines and keep the others. It seems (although your post is not entirely clear about what you want) that you only want to keep the first "field".

Here's a possible oneliner doing that:

$ echo ' > | 94.17.166.233:5060 | unknown | disabled | > | 94.17.201.7:5060 | unknown | disabled | > | 94.17.238.174:5060 | unknown | disabled | > | 94.17.25.93:5060 | unknown | disabled | > | 94.17.174.32:5070 | unknown | disabled | > | 94.17.153.2:5080 | unknown | disabled | > | 94.17.253.74:9999 | unknown | disabled | > | 94.17.78.65:5060 | unknown | disabled | > | 94.17.116.247:5060 | unknown | disabled | > | 94.17.201.223:5060 | unknown | disabled | > | 94.17.194.127:5060 | unknown | disabled | > | 94.17.157.165:5060 | unknown | disabled | > | 94.17.160.92:5060 | unknown | disabled | > | 94.17.248.40:5060 | unknown | disabled | > > ' | perl -ne ' > print "$1\n" if /\|\s+([\w.:]+)\s+/; > ' 94.17.166.233:5060 94.17.201.7:5060 94.17.238.174:5060 94.17.25.93:5060 94.17.174.32:5070 94.17.153.2:5080 94.17.253.74:9999 94.17.78.65:5060 94.17.116.247:5060 94.17.201.223:5060 94.17.194.127:5060 94.17.157.165:5060 94.17.160.92:5060 94.17.248.40:5060
If that's not what you want, please explain more.
  • Comment on Re: How to grep some string(IP:port) from text file and print into txt file
  • Download Code

Replies are listed 'Best First'.
Re^2: How to grep some string(IP:port) from text file and print into txt file
by Anonymous Monk on Mar 02, 2017 at 20:09 UTC
    ooops:
    $ echo '| foo:bar ' | perl -nle'print for /\|\s+([\w.:]+)\s+/;' foo:bar