473,396 Members | 1,827 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,396 software developers and data experts.

Parse multiple files...

3
I feel like a goon. I had a script that would do this but I deleted it long ago without even thinking. Please if someone could help I would REALLY appreciate it.

I'm looking for a script that will read all of the files in a directory and pull the data between two sets of tags and put it in a tab delimited file. Such as, find:

<span class."inv">(.+?)<\/span>
-AND-
<td class."lister">(.+?)<\/td>

Then write to a new file: $1 \t $2 \n (not sure if that's right)

If you're sitting on a script that does something similar I can probably edit it for my use, I just can't flat-out write it yet. Please and thank you!
Mar 18 '08 #1
2 1996
eWish
971 Expert 512MB
Please try and code it yourself and if you get stuck the we will be glad to assist you. Look into using the HTML::Parser.

--Kevin
Mar 18 '08 #2
drjay
3
Expand|Select|Wrap|Line Numbers
  1. $dir = "c:\\script";
  2. $outdir = "c:\\newfiles";
  3.  
  4. ### DO NOT EDIT BELOW ###
  5. $i=1;
  6. print "Opening $dir\n";
  7. opendir(DH,$dir);
  8. while (defined ( my $filename = readdir(DH))) {
  9.     $outfilename=">\\$outdir\\$filename";
  10.     print "Opening $filename\n";
  11.     open(FHI,$filename);
  12.     while (<FHI>) {
  13.         $html .= $_;
  14.     }
  15.     close(FHI);
  16.  
  17.     while ($html =~ s/<span2>(.+?)<\/span2>/$1/) {
  18.     $i++;
  19.     }
  20.     print "$i matches found in $filename\n";
  21.     print "Saving to $outfilename\n";
  22.     open(FHO, $outfilename);
  23.     print FHO ($html);
  24.     close(FHO);
  25. }
  26. print "Done\n";
Problem is it tries to open everything (even the . and .., lol), claims to have found the tags in everything, claims to save it to another file, but has succeeded in none of it.
Mar 19 '08 #3

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

Similar topics

19
by: Peter A. Schott | last post by:
I've got a file that seems to come across more like a dictionary from what I can tell. Something like the following format: ###,1,val_1,2,val_2,3,val_3,5,val_5,10,val_10...
1
by: Powell | last post by:
I have a requirement to return some information from a large number of xml files I have tried XSLT, which quickly gets overwhelmed. Found references to XQuery and it seems like it might work I...
10
by: dreamcatcher | last post by:
I want my program to parse INI files, only have little clue of how to do that, though, hope you guys might shed some light on this, thanx. for example:
7
by: akira | last post by:
Hello, I need to parse this XML file or XML stream . Is it possible to parse it with DOM reading each DataContainer one by one. <DataContainer> <name> </name> <birthDate> </birthDate>...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
5
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
36
by: rhys | last post by:
My Gurus and Angels -- Please pardon this old-school programmer, only recently enlightened to open-source, having been trapped in the convenience of proprietary lingos for way too long. My...
6
by: =?Utf-8?B?RGF2aWRN?= | last post by:
Hello, I have an XML file generated from a third party application that I would like to parse. Ideally, I plan on having a windows service setup to scan various folders for XML files and parse the...
0
by: Anish Chapagain | last post by:
Hi, i tried to compile the swig .i file but am having probel with the error: parse error before % token example.i 1. %module example 2. %{ 3. #include <header.h> 4. %}
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.