Hi all,
I need to extact the contents between two keywords(START and STOP in a file .
I cont get the logic how to take the contents...
Can anyone help me out!!! -
$dirname="D:\\Extra\\Perl\\Pat";
-
open(FH3, ">filelist.txt") || die "Can't create the report file";
-
open(FH4, ">report.txt") || die "Can't create the report file";
-
-
unless (opendir (DIR,"$dirname")){
-
print "Can't open the directory $dirname \n";
-
exit;
-
}
-
-
while ($file = readdir(DIR)) {
-
print FH3 "$file\n";
-
}
-
close(FH3);
-
-
#***************Actual code*********************
-
$write=0;
-
open (FH, qq*<filelist.txt*) || die "Can't find the filelist.txt";
-
while(chomp( $mfile=<FH>)) {
-
if (-e $mfile && $mfile=~/txt$/) {
-
open (FH1,"<$mfile");
-
while(<FH1>) {
-
if ($text =~ /START/)
-
}
-
}
-
}
-
}
-
7 1574
Thanks I found the solution to the Problem
And what were your findings?
*Hint: There are lots of people who visit forums like this because they are learning Perl. Granted, a bunch of people could look at your code and know why it wasn't working, but there are a number of people who aren't in the know. If you post a comment and find the solution before anyone can respond to you, then it is always a good idea, along with your notification that you solved your issue, to let everyone know "what" the solution was and any other pertinent details.
Regards,
Jeff
probably:
(/START/ .. /END/)
**DOH!** I knew that, I was just trying to get him/her into the practice of explaining the solution that they learned about instead of just saying, "Solve,sorry to bug you".
tThis is the solution that I found. I know the code is too big and it can be written in a more simpler way if anyone know the same let me know.
Purpse: To get all the lines between START and END for all files in a directory and store it another file. -
dirname="D:\\Extra\\Per\\Pat";
-
open(FH3, ">filelist.txt") || die "Can't create the report file";
-
open(FH4, ">report.txt") || die "Can't create the report file";
-
unless (opendir (DIR,"$dirname")){
-
print "Can't open the directory $dirname \n";
-
exit;
-
}
-
-
while ($file = readdir(DIR)){
-
print FH3 "$file\n";
-
}
-
close(FH3);
-
-
#***************Actual code*********************
-
$write=0;
-
open (FH, qq*<filelist.txt*) || die "Can't find the filelist.txt";
-
while (chomp($mfile = <FH>)) {
-
if (-e $mfile && $mfile=~/txt$/) {
-
open (FH1,"<$mfile");
-
while (<FH1>) {
-
if ($_ =~ /start/) {
-
$write=1;
-
}
-
-
if ($write) {
-
print FH4 "The Filename is $mfile $_";
-
if ($_=~/END/) {
-
$write=0;
-
}
-
}
-
}
-
}
-
}
-
-
close(FH4);
-
close(FH1);
-
Your code could be written differently and improved upon, but there is really nothing terribly wrong with your code. The worst mistake is not using the "strict" and "warnings" pragma.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rxl124 |
last post by:
Hi,
quick question,
how would you assign a contents to file in perl
i was thinking
$filename=`echo newvalue > filename`;
|
by: Frank B. |
last post by:
Is there anyway to write a folders contents to file?
-Frank B.
|
by: Deathwing |
last post by:
Hello,
I'm fairly new to python and have only been playing around with it for one week actually. It's my first attempt at programming and I'm trying to generate some random floats and then...
|
by: jDawg123 |
last post by:
Can somone plz give me some ideas on writing a perl script that reads the contents of files from a directory and outputs to an output file the areas in the files read from the directory that have two...
|
by: cdnmr |
last post by:
Hi, I am a newcomer to VB, (just about to complete my introductory course). I have developed a feedback form where users can input their personal details (name, telephone etc) as well as feedback...
|
by: grasshopper2 |
last post by:
I am looking to build a regular expression that will match pTOC(somenumber)
where the number varies between 1& ten, this is to generate a table of contents file that I desperately need to display...
|
by: Nash |
last post by:
Hi All,
I have set of data which needs to be stored in a file. The data is
classified into categories say Cat 1, Cat 2... Cat 10 each category
can have any number of entries. The program allows...
|
by: DR |
last post by:
how to search tfs by name of file or contents in file?
|
by: FredSovenix |
last post by:
Can anybody provide instruction or examples on how to access the noise words file using T-SQL? I want to be able to adjust the users' search string by eliminating the noise words, but if the...
|
by: Feivi18 |
last post by:
Hi everyone, new user here. I've been finding it harder and harder to get answers at EE for certain questions, and am hoping someone here will be able to help me!
Using asp.net and c#, my site...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |