in reply to Re^3: Using grep to pick out Specific lines in a text file
in thread Using grep to pick out Specific lines in a text file

Perfect, that worked great. Now that it is working i found another issue. In this where "singer" is i pulled 23 different occurances, i only need to print singer in my out put. That tells me that it does show up in the data log. And Singer does change to multiple values.

  • Comment on Re^4: Using grep to pick out Specific lines in a text file

Replies are listed 'Best First'.
Re^5: Using grep to pick out Specific lines in a text file
by ww (Archbishop) on Apr 11, 2013 at 21:40 UTC
    Think hash

    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re^5: Using grep to pick out Specific lines in a text file
by hdb (Monsignor) on Apr 12, 2013 at 07:01 UTC

    This is based on the assumption that after ...30.6511 (V6.5.1 FP1) comes one or more spaces, then a word (that you are looking for), some more spaces, an IP address, possibly some spaces before the end of line. You need to modify the regex should this assumption not hold.

    use strict; use warnings; use lib "/Library/Perl/5.10.0/"; use autodie; open FILE, "<", "data/04102013_loginlogs.txt" or die "Cannot open inpu +t file.\n"; open OUT, ">>", "output.txt" or die "Cannot open output file.\n"; my %found; while( my $line=<FILE> ) { $found{$1}++ if( $line =~ /unknown type\(0x134e\)\s+30\.6511\s ++\(V6\.5\.1 FP1\)\s+(.*)\s+\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s*$/ ); } print join( "|", keys %found), "\n"; close OUT; close FILE;

    I have used this test file:

    01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Singer 192.168.1.1 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Singer 192.168.1.1 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Runner 192.168.1.10 ddddd 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Singer 192.168.1.1 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Dancer 192.168.1.1 ddddd ffffff 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Singer 192.168.1.1 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Singer 192.168.1.1 01 XXXXXXXX 10/Apr/13 01:13:10 unknown type(0x134e) 30.6511 (V6.5.1 FP +1) Singer 192.168.1.1