07-12-2009
Perl: Printing Multiple Lines after pattern match
[SIZE=2][SIZE=2]Hello People,
Need some assistance/guidance.
OUTLINE:
Two files (File1 and File2)
File1 has some ids such as
009463_3922_1827
897654_8764_5432
File2 has things along the lines of:
Query= 009463_3922_1827 length=252
(252 letters)
More stufff here
Query= 009525_3967_2963 length=249 uaccno=FIFOXZ216JYL81
(249 letters)
AND MORE STUFF HERE
-----------
PROBLEM:
Capture/finding the Ids stored in File1 from file2 is trivial.
What I need to capture "also" is the remaining part.
For example:
This part of the code gives me the line when it has found the match: Query= 009463_3922_1827 length=252 uaccno=FIFOXZ216JUM5H
while ($line2=<INFILE2>)
{
if ($line2 =~ /$line1/)
{
print $line2;
}
Now how can I get to the other lines below this (Query= 009463_3922_1827 length=252 uaccno=FIFOXZ216JUM5H) line.
For example, everything until
Query= 009525_3967_2963 length=249 uaccno=FIFOXZ216JYL81
(249 letters)
>>>>>>>>>>>>>>>
a) Few ideas I can think of is using SEEK/tell.
Will this be a efficient way, how much to SEEK, the while loop is reading one line at a time so, some how buffer everything until see the pattern as Query=.....
How to find the bytes until then?
b) Using read()
How to find the number of byes after the pattern match?
c)Using the metacharacters to read ahead after the pattern match /ID (?=SOMETHING)/
Tried this but with until, but its not working. May be my regex is incorrect.
If any one can just be a push in the write direction--pseudocode etc. it would be much appreciated.
I am not reading the files or going to use array (copying the contents of a file to an array) as the files are big.
Last edited by Deep9000; 07-17-2009 at 09:57 AM..
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi all,
I've been working on a script which I have hit a road block now. I have written a script using sed to extract the below data and pumped into another file:
Severity............: MAJORWARNING
Summary:
System temperature is out of normal range.
Severity............: MAJORWARNING... (13 Replies)
Discussion started by: phixsius
13 Replies
2. Shell Programming and Scripting
Could any one tell me how to read and match multiple lines in perl? Did this code below still work in this situation?
while (<FILE>) {
if (/ /) {
}
}
Thanks a lot! (5 Replies)
Discussion started by: zx1106
5 Replies
3. Shell Programming and Scripting
Hi
I have a file (say 'file1')and I want to search for a first occurence of pattern (say 'ERROR') and print ten lines in the file below pattern. I have to code it in PERL and I am using Solaris 5.9.
I appreciate any help with code
Thanks
Ammu (6 Replies)
Discussion started by: ammu
6 Replies
4. Shell Programming and Scripting
I have sql file containing lot of queries on different database table. I have to filter specific table queries.
Let say i need all queries of test1,test2,test3 along with four lines above it and sql queries can be multi lines or in single line.
Input file contains.
set INSERT_ID=1;
set... (1 Reply)
Discussion started by: mirfan
1 Replies
5. Shell Programming and Scripting
Hi
I know sed and awk has options to give range of line numbers, but
I need to replace pattern in specific lines
Something like
sed -e '1s,14s,26s/pattern/new pattern/' file name
Can somebody help me in this....
I am fine with see/awk/perl
Thank you in advance (9 Replies)
Discussion started by: dani777
9 Replies
6. Shell Programming and Scripting
Hi, i have a big file having many opcodes.
if (opcode="01110000000100000000" ) then --fadd
result.opcode := "01110000000100000000";
result.s0 := '1';
result.s1 := '1';
result.s2 := '0';
result.inst := '0';
result.scalar := '1';... (7 Replies)
Discussion started by: twistedpair
7 Replies
7. Shell Programming and Scripting
'Hi
I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match.
Which option is to be used to exclude the line containing the pattern?
sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies
8. Shell Programming and Scripting
Hello Experts , require help . See below output:
File inputs
------------------------------------------
Server Host = mike
id rl images allocated last updated density
vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies
9. Shell Programming and Scripting
Not sure how I can accomplish this. I would like to remove all interfaces that have the commands I would like to see: switchport port-security, spanning-tree portfast. One line is no problem.
interface FastEthernet0/8
spanning-tree portfast
interface FastEthernet0/9
spanning-tree... (4 Replies)
Discussion started by: mrlayance
4 Replies
10. Shell Programming and Scripting
GM,
I have an issue at work, which requires a simple solution. But, after multiple attempts, I have not been able to hit on the code needed.
I am assuming that sed, awk or even perl could do what I need.
I have an application that adds extra blank page feeds, for multiple reports, when... (7 Replies)
Discussion started by: jxfish2
7 Replies
LEARN ABOUT DEBIAN
rdf::query::plan::distinct
RDF::Query::Plan::Distinct(3pm) User Contributed Perl Documentation RDF::Query::Plan::Distinct(3pm)
NAME
RDF::Query::Plan::Distinct - Executable query plan for Distincts.
VERSION
This document describes RDF::Query::Plan::Distinct version 2.908.
METHODS
Beyond the methods documented below, this class inherits methods from the RDF::Query::Plan class.
"new ( $plan )"
"execute ( $execution_context )"
"next"
"close"
"pattern"
Returns the query plan that will be used to produce the data to be made distinct.
"distinct"
Returns true if the pattern is guaranteed to return distinct results.
"ordered"
Returns true if the pattern is guaranteed to return ordered results.
"plan_node_name"
Returns the string name of this plan node, suitable for use in serialization.
"plan_prototype"
Returns a list of scalar identifiers for the type of the content (children) nodes of this plan node. See RDF::Query::Plan for a list of
the allowable identifiers.
"plan_node_data"
Returns the data for this plan node that corresponds to the values described by the signature returned by "plan_prototype".
"graph ( $g )"
AUTHOR
Gregory Todd Williams <gwilliams@cpan.org>
perl v5.14.2 2012-01-31 RDF::Query::Plan::Distinct(3pm)