473,388 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Need to match a value and print the subsequent lines to output

Hello,

I am noob to Perl Programming. Here's what I need to do. I need to match a string value from a file and upon matching the value, I need the remainder of the file to be printed to an output.

For example: Here's the File I'll be reading:

Hilton also told Superior Court Judge Michael T. Sauer she was trying to take more responsibility for her life. This, after Hilton essentially laid the blame for her troubles on longtime publicist Elliot Mintz, whom she said told her the license was only suspended for 30 days, through last December, while it had actually been suspended into March.


Value to match = Elliot

Reqd Output:

Elliot Mintz, whom she said told her the license was only suspended for 30 days, through last December, while it had actually been suspended into March.


Here's the code i have so far:

open (FILE, "$infile") or die "Cannot Open Log File!\n";
open (DAT,">$outfile") || die("Cannot Open File");

while (@variable = <FILE>) {
for (@variable =~ /Building Configuration/) {
# write to the data file
print DAT "@variable\n";
}
}
close DAT;
close FILE;
May 7 '07 #1
2 1206
KevinADC
4,059 Expert 2GB
Is this school/class work?
May 7 '07 #2
jjeanj1
18
hi this is what i have i saw your post and i remember i had a samll routine that does that. You can try that. Tell me if you need more info.

$INPUT = "input.txt";
$outfile ="out.txt";

open(INPUT) or die("Could not open input file.");
open (DAT,">$outfile") || die("Cannot Open File");

foreach $line (<INPUT>) {
chomp($line);
if($line=~ /(\Elliot)/){ # do line-by-line processing.
print DAT "$line\n";
}


}
close(INPUT);
May 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
2
by: Joh | last post by:
Hello, (sorry long) i think i have missed something in the code below, i would like to design some kind of detector with python, but i feel totally in a no way now and need some advices to...
2
by: Andrew Rich | last post by:
Howdy, I have a need to do this :- 1. find a match 2. go back three lines 3. read out lines 1 2 3 eg
1
by: Lothar Lemnitzer | last post by:
Dear fellows, I have a problem with matching namespaces in an XML document and an XSLT stylesheet (at least I think that this is the source of trouble). My XML document looks like this: 1...
4
by: Johnny Lee | last post by:
Hi, I've met a problem in match a regular expression in python. Hope any of you could help me. Here are the details: I have many tags like this: xxx<a href="http://xxx.xxx.xxx" xxx>xxx xxx<a...
17
by: EkteGjetost | last post by:
This is definitely not the smart thing to do as far as my learning goes, but desperate situations call for desperate measures. The final lab for my introduction to C programming class is due...
14
by: philbo30 | last post by:
Silly question, I know, but I have a code snippet that looks like this: printf("blah blah"); printf("more blah"); x = a + b - c; printf($%3.2f\n", x); y = d + e; printf($%3.2f\n, y);
4
by: J | last post by:
I've spent most of the day on this, and I just can't seem to find a solution, please help me! :) I'm recieving XML that I can't modify that looks like: <?xml version="1.0"?> <Doc> <Page>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.