Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2011
    Posts
    31
    Thanks
    25
    Thanked 0 Times in 0 Posts

    How Do I do AND with grep?

    Hi,
    I’m trying to use GREP on (windows) , looking for help anywhere I can.
    I want to write a grep script that would match “this and that” in small files (like 30-70 lines).
    Need an example.
    Thanks, vl123456

  • #2
    New Coder
    Join Date
    Mar 2011
    Posts
    31
    Thanks
    25
    Thanked 0 Times in 0 Posts
    Hi
    Here what I got, it works but does not look god.
    Thanks, vl123456

    Code:
    #!/usr/bin/perl -w
    use strict;
    use warnings;
    
    my $word0 = 'this' ;
     my $word1 = ’that’ ;
     my $word2 =  ‘something else' ;
     my $word3 = ‘one more thing’ ;
     my $word4 = ‘those’ ;
     my $word5 = ‘here it is’  ;
    
     my $readfile  = "C:\\Temp.txt" ;  
     open(MYINPUTFILE, "<$readfile")|| die "Can't open 'Temp.txt'\n" ;
     my @filedata = <MYINPUTFILE> ;
    
          my @ word1=  (grep/$word1/gi, @filedata);
          my @ word2=  (grep/$word2/gi,@filedata) ;
          my @ word3=   (grep/$word3/gi,@filedata) ;
          my @ word4= (grep/$word4/gi,@filedata) ;      
          my @ word5= (grep/$word5/gi,@filedata) ;
    
    if (@word1&& @ word2)
      {do this}
    	if (@word1&& @ word2)
      {do that}
    if (@word1&& @ word4)
      {do this}
    	if (@word3&& @ word5)
      {do that}
    	if (@word1&& @ word5)
      {do that}
    
    close MYINPUTFILE ;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •