Sponsored Content
Top Forums Shell Programming and Scripting Perl - How to search a text file with multiple patterns? Post 302301051 by KevinADC on Wednesday 25th of March 2009 05:23:00 PM
Old 03-25-2009
Code:
!/usr/bin/perl
use warnings;
use strict;

use strict;
use warnings;

my $identity = 'Joseph|Clark|May';
my $data_file = 'C:/tests/Profiles.txt';
open (DAT, $data_file) or die "$!";
OUTTER: while (<DAT>) {
   if (/^NAME $identity$/) {
      print; 
      while(<DAT>) {
         print;
         next OUTTER if (m|//|);
      } 
   }
}

close (DAT);

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to parameterize multiple search patterns and generate a new file

I have one file: 123*100*abcd*10 123*101*abcd*-29*def 123*100*abcd*-10 123*102*abcd*-105*asd I would like to parameterize the search patterns in the following way so that the user could dynamically change the search pattern. *100* and *- (ie *minus) *102* and *- The output that is... (6 Replies)
Discussion started by: augustinep
6 Replies

2. Shell Programming and Scripting

Perl: Match a line with multiple search patterns

Hi I'm not very good with the serach patterns and I'd need a sample how to find a line that has multiple patterns. Say I want to find a line that has "abd", "123" and "QWERTY" and there can be any characters or numbers between the serach patterns, I have a file that has thousands of lines and... (10 Replies)
Discussion started by: Juha
10 Replies

3. UNIX for Advanced & Expert Users

Best way to search for patterns in huge text files

I have the following situation: a text file with 50000 string patterns: abc2344536 gvk6575556 klo6575556 .... and 3 text files each with more than 1 million lines: ... 000000 abc2344536 46575 0000 000000 abc2344536 46575 4444 000000 abc2344555 46575 1234 ... I... (8 Replies)
Discussion started by: andy2000
8 Replies

4. Shell Programming and Scripting

Search multiple patterns in multiple files

Hi, I have to write one script that has to search a list of numbers in certain zipped files. For eg. one file file1.txt contains the numbers. File1.txt contains 5,00,000 numbers and I have to search each number in zipped files(The number of zipped files are around 1000 each file is 5 MB) I have... (10 Replies)
Discussion started by: vsachan
10 Replies

5. Shell Programming and Scripting

search multiple patterns

I have two lists in a file that look like a b b a e f c d f e d c I would like a final list a b c d e f I've tried multiple grep and awk but can't get it to work (8 Replies)
Discussion started by: godzilla07
8 Replies

6. Shell Programming and Scripting

How to search Multiple patterns in unix

Hi, I tried to search multiple pattern using awk trans=1234 reason=LN MISMATCH rec=`awk '/$trans/ && /'"$reason"'/' file` whenevr i tried to run on command promt it is executing but when i tried to implment same logic in shell script,it is failing i.e $rec is empty ... (6 Replies)
Discussion started by: ns64110
6 Replies

7. Shell Programming and Scripting

Search and swap multiple lines in file using Perl

Hi all, I have a vcd file with a bunch of lines containing an array, like this $var wire 1 b a $end $var wire 1 c a $end $var wire 1 d a $end $var wire 1 e a $end $var wire 1 f b $end $var wire 1 g b $end $var wire 1 h b $end $var wire 1 i b $end I want it like this: $var wire 1 e a... (12 Replies)
Discussion started by: veerabahu
12 Replies

8. Shell Programming and Scripting

How to search multiple patterns and remove lines from a file?

Hi, I have a file content as below. Table : PAYR Displayed fields: 15 of 15 Fixed columns: 4 List width 0999... (4 Replies)
Discussion started by: shirdi
4 Replies

9. Shell Programming and Scripting

Search patterns in multiple logs parallelly.

Hi All, I am starting a service which will redirect its out put into 2 logs say A and B. Now for succesful startup of the service i need to search pattern1 in log A and pattern2 in log B which are writen continuosly. Now my requirement is to find the patterns in the increasing logs A and B... (19 Replies)
Discussion started by: Girish19
19 Replies

10. Shell Programming and Scripting

Search Multiple patterns and display

Hi, I have scenario like below and need to search for multiple patterns Eg: Test Time Started= secs Time Ended = secc Green test Test Time Started= secs Time Ended = secc Green test Output: I need to display the text starting with Test and starting with Time... (2 Replies)
Discussion started by: weknowd
2 Replies
MARC::Batch(3pm)					User Contributed Perl Documentation					  MARC::Batch(3pm)

NAME
MARC::Batch - Perl module for handling files of MARC::Record objects SYNOPSIS
MARC::Batch hides all the file handling of files of "MARC::Record"s. "MARC::Record" still does the file I/O, but "MARC::Batch" handles the multiple-file aspects. use MARC::Batch; # If you have werid control fields... use MARC::Field; MARC::Field->allow_controlfield_tags('FMT', 'LDX'); my $batch = MARC::Batch->new( 'USMARC', @files ); while ( my $marc = $batch->next ) { print $marc->subfield(245,"a"), " "; } EXPORT
None. Everything is a class method. METHODS
new( $type, @files ) Create a "MARC::Batch" object that will process @files. $type must be either "USMARC" or "MicroLIF". If you want to specify "MARC::File::USMARC" or "MARC::File::MicroLIF", that's OK, too. "new()" returns a new MARC::Batch object. @files can be a list of filenames: my $batch = MARC::Batch->new( 'USMARC', 'file1.marc', 'file2.marc' ); Your @files may also contain filehandles. So if you've got a large file that's gzipped you can open a pipe to gzip and pass it in: my $fh = IO::File->new( 'gunzip -c marc.dat.gz |' ); my $batch = MARC::Batch->new( 'USMARC', $fh ); And you can mix and match if you really want to: my $batch = MARC::Batch->new( 'USMARC', $fh, 'file1.marc' ); next() Read the next record from that batch, and return it as a MARC::Record object. If the current file is at EOF, close it and open the next one. "next()" will return "undef" when there is no more data to be read from any batch files. By default, "next()" also will return "undef" if an error is encountered while reading from the batch. If not checked for this can cause your iteration to terminate prematurely. To alter this behavior, see "strict_off()". You can retrieve warning messages using the "warnings()" method. Optionally you can pass in a filter function as a subroutine reference if you are only interested in particular fields from the record. This can boost performance. strict_off() If you would like "MARC::Batch" to continue after it has encountered what it believes to be bad MARC data then use this method to turn strict OFF. A call to "strict_off()" always returns true(1). "strict_off()" can be handy when you don't care about the quality of your MARC data, and just want to plow through it. For safety, "MARC::Batch" strict is ON by default. strict_on() The opposite of "strict_off()", and the default state. You shouldn't have to use this method unless you've previously used "strict_off()", and want it back on again. When strict is ON calls to next() will return undef when an error is encountered while reading MARC data. strict_on() always returns true(1). warnings() Returns a list of warnings that have accumulated while processing a particular batch file. As a side effect the warning buffer will be cleared. my @warnings = $batch->warnings(); This method is also used internally to set warnings, so you probably don't want to be passing in anything as this will set warnings on your batch object. "warnings()" will return the empty list when there are no warnings. warnings_off() Turns off the default behavior of printing warnings to STDERR. However, even with warnings off the messages can still be retrieved using the warnings() method if you wish to check for them. "warnings_off()" always returns true(1). warnings_on() Turns on warnings so that diagnostic information is printed to STDERR. This is on by default so you shouldn't have to use it unless you've previously turned off warnings using warnings_off(). warnings_on() always returns true(1). filename() Returns the currently open filename or "undef" if there is not currently a file open on this batch object. RELATED MODULES
MARC::Record, MARC::Lint TODO
None yet. Send me your ideas and needs. LICENSE
This code may be distributed under the same terms as Perl itself. Please note that these modules are not products of or supported by the employers of the various contributors to the code. AUTHOR
Andy Lester, "<andy@petdance.com>" perl v5.10.1 2010-03-29 MARC::Batch(3pm)
All times are GMT -4. The time now is 06:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy