Sponsored Content
Top Forums Programming Perl:how to find multiple strings Post 302511774 by auto_w on Thursday 7th of April 2011 01:47:48 PM
Old 04-07-2011
Perl:how to find multiple strings

Hi , i'm trying to find lines in a file that have 2 matches,but i have trouble with regex -it doesn't search for a second string-please help
Code:
#!/usr/bin/perl -w
use strict;
use warnings;

my $log = "log";
my $log_string = "grep '^8=' $log |";
usage ();
chomp (my $TAB_1 = $ARGV[0]);
chomp (my $TAB_5 = $ARGV[1]); 
open (my $HAN, "$log_string") || die "Problems grepin... : $!";
my @contents = <$HAN>;
my $matches = grep /1=$TAB_1 && 5=$TAB_5/, @contents ;
 foreach (@matches) 
   { 
      print "[+] FOUND $TAB_1 and $TAB_5 in\n",
"-----------------------\n",
"$_" ;}

now you can do it like
Code:
foreach (@contents)
if /1=$TAB_1 && 5=$TAB_5 /

that also doesn't find lines with those 2 matches

Last edited by radoulov; 04-08-2011 at 04:36 PM.. Reason: Code tags!
 

10 More Discussions You Might Find Interesting

1. Linux

To find multiple strings count in a file

I need to find the line count of multiple strings in a particular file. The strings are as follows: bmgcc bmgccftp bsmsftp bulkftp cctuneftp crbtftp crmpos cso gujhr I am doing manual grep for each of the string to find the line count. The command i am using right now is: grep mark... (3 Replies)
Discussion started by: salaathi
3 Replies

2. UNIX for Dummies Questions & Answers

grep command to find multiple strings in multiple lines in a file.

I want to search files (basically .cc files) in /xx folder and subfolders. Those files (*.cc files) must contain #include "header.h" AND x() function. I am writing it another way to make it clear, I wanna list of *.cc files that have 'header.h' & 'x()'. They must have two strings, header.h... (2 Replies)
Discussion started by: ritikaSharma
2 Replies

3. UNIX for Dummies Questions & Answers

how to find and replace strings in multiple files

Hi All, Iam new to unix, I need to find string and replace it in the file name. Like text_123_0.txt,text_123_1.txt,text_123_2.txt. I need to search 123 and replace it with 234 . Is there any unix command to replace them in single command since i have 5 directories. So i need to go each and every... (0 Replies)
Discussion started by: etldeveloper
0 Replies

4. UNIX for Dummies Questions & Answers

Find Multiple Strings from a list of *.gz files withour decompressing...

Hello Team, There is this situation where there are around 20 *.gz files and i want to search multiple words from all those files. Example as below : filea.gz fileb.gz filec.gz now i want to search words "hi" and "hello" from all these 3 files without... (4 Replies)
Discussion started by: varun87
4 Replies

5. Shell Programming and Scripting

Find position of character in multiple strings in a file

Greetings. I have a file with information like this: AMNDHRKEOEU?AMNDHRKEOEU?AMNDHRKEOEU?AMNDHRKEOEU? AMNDHRKEEU?AMNDHREOEU? AMNDHREU?AHRKEOEU?AMNDHRKEU?AMNDKEOEU? What I need to extract is the position, in every line, of every occurrence of '?' A desired output would be something... (6 Replies)
Discussion started by: Twinklefingers
6 Replies

6. Shell Programming and Scripting

How to find multiple strings within files under a directory

Hi guys, I need to find multiple strings within files under a directory and secondly, to count how many files are there with these strings. At present, i am able to do this in order to find one string (for example "abc"): find <path> -exec grep "abc" {} /dev/null \; Now for example, i... (2 Replies)
Discussion started by: frum
2 Replies

7. Shell Programming and Scripting

Find multiple strings and replace single string

Hi, following Perl code i used for finding multiple strings and replace with single string. code: #!/usr/bin/perl my @files = <*.txt>; foreach $fileName (@files) { print "$fileName\n"; my $searchStr = ',rdata\)' | ',,rdata\)' | ', ,rdata\)'; my $replaceStr =... (2 Replies)
Discussion started by: chettyravi
2 Replies

8. Solaris

How to find multiple strings on different lines in file?

Hello, I have spent considerable amount of time breaking my head on this and reached out here. here is the back ground. OS - Solaris 10 There are two strings '<Orin>sop' and '<Dup>two' which I wanted to look for in a file without the quotes on different lines and ONLY if both strings are... (5 Replies)
Discussion started by: keithTait309875
5 Replies

9. Shell Programming and Scripting

Perl script to find process and exclude strings from the output

Hi team, I'm a newbie of Perl Script and looking to create a simple perl script that will run in the Linux system: 1) to find process, such as ps -ef | grep process name 2) to exclude strings from the output if it found, for instance if i see abc from usr process, then will exclude it from... (1 Reply)
Discussion started by: hoffman2503
1 Replies

10. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies
Weather::Com::Finder(3pm)				User Contributed Perl Documentation				 Weather::Com::Finder(3pm)

NAME
Weather::Com::Finder - finder class to search for weather.com location's SYNOPSIS
#!/usr/bin/perl -w use Weather::Com::Finder; # you have to fill in your ids from weather.com here my $PartnerId = 'somepartnerid'; my $LicenseKey = 'mylicense'; my %weatherargs = ( 'partner_id' => $PartnerId, 'license' => $LicenseKey, ); my $finder = Weather::Com::Finder->new(%weatherargs); # if you want an array of locations: my @locations = $finder->find('Heidelberg'); # or if you prefer an arrayref: my $locations = $finder->find('Heidelberg'); foreach my $location (@locations) { print "Found weather for city: ", $location->name(), " "; print "Current Conditions are ", $location->current_conditions()->description(), " "; } DESCRIPTION
The usual way to use the Weather::Com module would be to instantiate a Weather::Com::Finder that allows you to search for a location by providing a search string or postal code or any other search string that weather.com understands. The finder returns an arrayref or an array of locations (depending on how you call the "find()" method). Each location is an object of Weather::Com::Location. CONSTRUCTOR
new(hash or hashref) The constructor takes a configuration hash or hashref as described in the Weather::Com POD. Please refer to that documentation for further details. METHODS
find(search string) Once you've instantiated a finder object, you can perform "find()" calls to search for locations in the weather.com database. The "find()" method returns an array of Weather::Com::Location objects if you call it in list context, else an arrayref. Returns undef if no matching location could be found. SEE ALSO
See also documentation of Weather::Com and Weather::Com::Location. AUTHOR
Thomas Schnuecker, <thomas@schnuecker.de> COPYRIGHT AND LICENSE
Copyright (C) 2004-2007 by Thomas Schnuecker This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The data provided by weather.com and made accessible by this OO interface can be used for free under special terms. Please have a look at the application programming guide of weather.com (http://www.weather.com/services/xmloap.html) perl v5.8.8 2007-07-09 Weather::Com::Finder(3pm)
All times are GMT -4. The time now is 06:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy