473,616 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Remove Header info, add date, merge files

1 New Member
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!
Feb 12 '08 #1
1 1993
bvdet
2,851 Recognized Expert Moderator Specialist
Something like this:
Expand|Select|Wrap|Line Numbers
  1. import re, os
  2.  
  3. dir_name = 'your_directory'
  4.  
  5. def combine_files(dir_name, fn, prefix):
  6.     fileList = []
  7.     for file in os.listdir(dir_name):
  8.         dirfile = os.path.join(dir_name, file)
  9.         if os.path.isfile(dirfile):
  10.             fileList.append(dirfile)
  11.     patt = re.compile(r'\d{2}:')
  12.     outList = []
  13.     for f in fileList:
  14.         print 'Parsing file %s' % f
  15.         for line in open(f).readlines():
  16.             if patt.match(line):
  17.                 outList.append(' '.join([prefix, line.strip()]))
  18.     ff = open(fn, 'w')
  19.     ff.write('\n'.join(outList))
  20.     ff.close()
  21.  
  22. combine_files(dir_name, 'combined.dat', '2008-06-01')
Feb 12 '08 #2

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

Similar topics

4
2513
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...
0
1308
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...
31
4576
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...
2
6581
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...
0
8199
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, 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...
0
8145
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,...
0
8642
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, 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...
0
8592
jinu1996
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...
0
8448
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 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...
0
7118
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, 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...
1
6097
isladogs
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...
0
5550
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();...
0
4060
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...

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.