Cat/grep just the lines with single ip

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a file something like this



Script http://127.0.0.1/ blabla
127.0.0.1
Script 127.0.0.2/index.html bla bla
127.0.0.2
Script 127.0.0.3/contact bla bla
Script 127.0.0.4/settings bla bla
127.0.0.4


I want to get only the lines that contain just a single ip not all the ips from all the lines.



How can i do this?



the results should be



127.0.0.1
127.0.0.2
127.0.0.4






share|improve this question

























    up vote
    0
    down vote

    favorite












    I have a file something like this



    Script http://127.0.0.1/ blabla
    127.0.0.1
    Script 127.0.0.2/index.html bla bla
    127.0.0.2
    Script 127.0.0.3/contact bla bla
    Script 127.0.0.4/settings bla bla
    127.0.0.4


    I want to get only the lines that contain just a single ip not all the ips from all the lines.



    How can i do this?



    the results should be



    127.0.0.1
    127.0.0.2
    127.0.0.4






    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have a file something like this



      Script http://127.0.0.1/ blabla
      127.0.0.1
      Script 127.0.0.2/index.html bla bla
      127.0.0.2
      Script 127.0.0.3/contact bla bla
      Script 127.0.0.4/settings bla bla
      127.0.0.4


      I want to get only the lines that contain just a single ip not all the ips from all the lines.



      How can i do this?



      the results should be



      127.0.0.1
      127.0.0.2
      127.0.0.4






      share|improve this question













      I have a file something like this



      Script http://127.0.0.1/ blabla
      127.0.0.1
      Script 127.0.0.2/index.html bla bla
      127.0.0.2
      Script 127.0.0.3/contact bla bla
      Script 127.0.0.4/settings bla bla
      127.0.0.4


      I want to get only the lines that contain just a single ip not all the ips from all the lines.



      How can i do this?



      the results should be



      127.0.0.1
      127.0.0.2
      127.0.0.4








      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 13 at 8:41
























      asked Jun 13 at 8:37









      Killroy2018

      346




      346




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The cat utility just concatenates the data given to it, so it would not be of much use here.



          Assuming it's ok to be somewhat sloppy with what constitutes a valid IP address:



          grep -Ex '([0-9]1,3.)3[0-9]1,3' file


          This would match and print any lines matching the given regular expression (and discard the others).



          An even sloppier solution would be to discard lines that contains anything but dots and digits:



          grep -v '[^0-9.]' file


          Depending on your requirements, one of these would be enough.



          For a completely correct regular expression (does not match invalid IP addresses), you could use



          grep -Ex '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]).)3(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' file





          share|improve this answer























          • none of those work...
            – Killroy2018
            Jun 13 at 8:58











          • cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
            – Killroy2018
            Jun 13 at 8:59










          • root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
            – Killroy2018
            Jun 13 at 9:03










          • @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
            – Kusalananda
            Jun 13 at 9:13










          • sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
            – Killroy2018
            Jun 13 at 9:15











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f449477%2fcat-grep-just-the-lines-with-single-ip%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          The cat utility just concatenates the data given to it, so it would not be of much use here.



          Assuming it's ok to be somewhat sloppy with what constitutes a valid IP address:



          grep -Ex '([0-9]1,3.)3[0-9]1,3' file


          This would match and print any lines matching the given regular expression (and discard the others).



          An even sloppier solution would be to discard lines that contains anything but dots and digits:



          grep -v '[^0-9.]' file


          Depending on your requirements, one of these would be enough.



          For a completely correct regular expression (does not match invalid IP addresses), you could use



          grep -Ex '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]).)3(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' file





          share|improve this answer























          • none of those work...
            – Killroy2018
            Jun 13 at 8:58











          • cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
            – Killroy2018
            Jun 13 at 8:59










          • root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
            – Killroy2018
            Jun 13 at 9:03










          • @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
            – Kusalananda
            Jun 13 at 9:13










          • sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
            – Killroy2018
            Jun 13 at 9:15















          up vote
          1
          down vote



          accepted










          The cat utility just concatenates the data given to it, so it would not be of much use here.



          Assuming it's ok to be somewhat sloppy with what constitutes a valid IP address:



          grep -Ex '([0-9]1,3.)3[0-9]1,3' file


          This would match and print any lines matching the given regular expression (and discard the others).



          An even sloppier solution would be to discard lines that contains anything but dots and digits:



          grep -v '[^0-9.]' file


          Depending on your requirements, one of these would be enough.



          For a completely correct regular expression (does not match invalid IP addresses), you could use



          grep -Ex '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]).)3(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' file





          share|improve this answer























          • none of those work...
            – Killroy2018
            Jun 13 at 8:58











          • cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
            – Killroy2018
            Jun 13 at 8:59










          • root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
            – Killroy2018
            Jun 13 at 9:03










          • @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
            – Kusalananda
            Jun 13 at 9:13










          • sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
            – Killroy2018
            Jun 13 at 9:15













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          The cat utility just concatenates the data given to it, so it would not be of much use here.



          Assuming it's ok to be somewhat sloppy with what constitutes a valid IP address:



          grep -Ex '([0-9]1,3.)3[0-9]1,3' file


          This would match and print any lines matching the given regular expression (and discard the others).



          An even sloppier solution would be to discard lines that contains anything but dots and digits:



          grep -v '[^0-9.]' file


          Depending on your requirements, one of these would be enough.



          For a completely correct regular expression (does not match invalid IP addresses), you could use



          grep -Ex '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]).)3(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' file





          share|improve this answer















          The cat utility just concatenates the data given to it, so it would not be of much use here.



          Assuming it's ok to be somewhat sloppy with what constitutes a valid IP address:



          grep -Ex '([0-9]1,3.)3[0-9]1,3' file


          This would match and print any lines matching the given regular expression (and discard the others).



          An even sloppier solution would be to discard lines that contains anything but dots and digits:



          grep -v '[^0-9.]' file


          Depending on your requirements, one of these would be enough.



          For a completely correct regular expression (does not match invalid IP addresses), you could use



          grep -Ex '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]).)3(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])' file






          share|improve this answer















          share|improve this answer



          share|improve this answer








          edited Jun 13 at 9:39


























          answered Jun 13 at 8:44









          Kusalananda

          101k13199312




          101k13199312











          • none of those work...
            – Killroy2018
            Jun 13 at 8:58











          • cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
            – Killroy2018
            Jun 13 at 8:59










          • root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
            – Killroy2018
            Jun 13 at 9:03










          • @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
            – Kusalananda
            Jun 13 at 9:13










          • sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
            – Killroy2018
            Jun 13 at 9:15

















          • none of those work...
            – Killroy2018
            Jun 13 at 8:58











          • cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
            – Killroy2018
            Jun 13 at 8:59










          • root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
            – Killroy2018
            Jun 13 at 9:03










          • @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
            – Kusalananda
            Jun 13 at 9:13










          • sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
            – Killroy2018
            Jun 13 at 9:15
















          none of those work...
          – Killroy2018
          Jun 13 at 8:58





          none of those work...
          – Killroy2018
          Jun 13 at 8:58













          cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
          – Killroy2018
          Jun 13 at 8:59




          cat putty.txt | grep -v '[^0-9.]' Binary file (standard input) matches
          – Killroy2018
          Jun 13 at 8:59












          root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
          – Killroy2018
          Jun 13 at 9:03




          root@localhost:~# grep -Ex '([0-9]1,3.)3[0-9]1,3' putty.txt root@localhost:~#
          – Killroy2018
          Jun 13 at 9:03












          @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
          – Kusalananda
          Jun 13 at 9:13




          @Killroy2018 I've tested all of these on the data you provided, and they all work. If grep is saying that the file is "binary", then you are not working with a text file, and certainly not the file that you posted.
          – Kusalananda
          Jun 13 at 9:13












          sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
          – Killroy2018
          Jun 13 at 9:15





          sorry mate, you are right, if i test it with my example or similar it works fine. I have to see the particularities of my specific file as i cand give a real sample. It is the saved output from putty, it is text
          – Killroy2018
          Jun 13 at 9:15













           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f449477%2fcat-grep-just-the-lines-with-single-ip%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?