Hi Folks,
I am working on a little project and hoping someone out there might offer me some info/insight. I have a folder containing about 50 html files where the contents look like this:
Astronomical Applications Dept.
U.S. Naval Observatory
Washington, DC 20392-5420
ST. PETER'S NOVA SCOTIA
o , o ,
W 60 52, N45 39
Altitude and Azimuth of the Sun
Jun 1, 2008
Zone: 3h West of Greenwich
Altitude Azimuth
(E of N)
h m o o
03:55 -11.6 40.5
04:00 -11.0 41.6
04:05 -10.4 42.6
04:10 -9.9 43.6
04:15 -9.2 44.6
04:20 -8.6 45.6
04:25 -8.0 46.6
04:30 -7.4 47.5
04:35 -6.7 48.5
04:40 -6.0 49.5
04:45 -5.4 50.4
04:50 -4.7 51.4
04:55 -4.0 52.3
05:00 -3.3 53.2
05:05 -2.6 54.1
05:10 -1.9 55.0
05:15 -1.2 56.0
05:20 0.1 56.9
05:25 0.7 57.8
05:30 1.4 58.6
05:35 2.1 59.5
05:40 2.8 60.4
What I need to do is remove the header info from each file, and add a date in front of each remaining line so that it looks like this:
2008-06-01 03:55 -11.6 40.5
Finally, I need to merge all the info from these individual files into one master.dat file.
If anyone can offer some advice on how I would be able to do this, that would be awesome.
Thanks Very Much!
1 1993 bvdet 2,851
Recognized Expert Moderator Specialist
Something like this: - import re, os
-
-
dir_name = 'your_directory'
-
-
def combine_files(dir_name, fn, prefix):
-
fileList = []
-
for file in os.listdir(dir_name):
-
dirfile = os.path.join(dir_name, file)
-
if os.path.isfile(dirfile):
-
fileList.append(dirfile)
-
patt = re.compile(r'\d{2}:')
-
outList = []
-
for f in fileList:
-
print 'Parsing file %s' % f
-
for line in open(f).readlines():
-
if patt.match(line):
-
outList.append(' '.join([prefix, line.strip()]))
-
ff = open(fn, 'w')
-
ff.write('\n'.join(outList))
-
ff.close()
-
-
combine_files(dir_name, 'combined.dat', '2008-06-01')
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andrew Ward |
last post by:
Hi All,
I was wondering if it is possible to use precompiled headers without having
to include a <stdafx.h> or whatever in every source file.
My problem is that I have a project that makes heavy usage of a large third
party library which means after pre-processing each translation unit is
around 1meg in size. There are reasons though why I cannot use the standard
approach to precompiled headers.
What I would like to do is somthing like...
|
by: Shrage H. Smilowitz |
last post by:
Hi,
I have created a setup project in vs.net, i have included several merge
modules, but when i test the installation on my development machine i dont
want the uninstall to remove the files that are included in the merge
modules, because it remove the files necossary to for development. How can i
prevent the uninstall from removing that files. I know that normal project
files i can set the permanent property to true and will not be...
|
by: Extremest |
last post by:
I have a loop that is set to run as long as the arraylist is > 0.
at the beginning of this loop I grab the first object and then
remove it. I then go into another loop that checks to see if there
are more objects that match the first object that i grabbed. If
they match then I put them in an array. I would like to remove each
match from the arraylist as I find them to speed things up and so
that they don't get checked again. If I try...
|
by: Cliff72 |
last post by:
I'm creating a database that will be uploading some text files into an
access table. The problem is that the text files have a header which
messes up my import specs. so what i have had to do is to open the
files and manually delete the data before importing them. Is there a
way i can programatically do this? ie programmatically edit the text
file and remove the surplus header text, and then import the file with
the DoCmd.TransferText...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| | |