Re: [SLUG] grep does not put the filename in front of every match

From: Kwan Lowe (kwan@digitalhermit.com)
Date: Wed Mar 02 2005 - 18:41:37 EST


Alex Harris wrote:
> I am trying to search several hundred files for ip addresses.
> These are text files with a bunch of words and the ip addresses are
> interspered at random
> Here are examples:
> -----------file1-------------------
> machine 1 is 10.30.41.6 and machine b is 192.168.3.6
> machine c is 10.6.4.3 good to know machine 1 and b
> ------------------------------------
> -----------file2--------------------
> machine 4 is 10.30.41.7 and machine b is 192.168.3.9
> machine d is 10.6.4.3 and hates to know machine 1 and b
> machine 5 is 10.30.41.3 and machine b is 192.168.3.0
> --------------------------------------
>
> When I grep for the ip addresses the output is as follows:
> file1:10.30.41.6
> 192.168.3.6
> file1:10.6.4.3
> file2:10.30.41.7
> 192.168.3.9
> file2:10.6.4.3
> file2: 10.30.41.3
> Esentially grep will not put the filename in front of the second
> occurance of an ip on a line.
> I need a way to figure out how to have the filename be displayed on
> the lines it's currently missing.
>
> In case it helps, the current grep command is:
> egrep -Ho "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" *

Odd... My grep will preface each line with the filename when I give the
-H option as you have. Running your command on some random text files
gives the filenames also.

-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 20:14:54 EDT