473,574 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file writing

2 New Member
Hi,thanks 4 the previous help.
my problem is I have some data like this in a file=


I need to develop a programme,which will create multiple files according to the AB number (like AB:569587 will be one file)
and put each sequence in their corresponding files.like:


this sequence will be put in the AB:1569854 file.

I have so far made a code which makes files according to the AB numbers,that is:

Expand|Select|Wrap|Line Numbers
  1. ..
  3. #!usr/bin/perl -w
  4. open(FH,"h.txt")or die "cant open file";
  5. @a=<FH>;
  6. foreach $line(@a){
  7. open(FHO,">$line") ;
  8.                  }
  10. close FH;
  11. close FHO;
  13. ..
But I really dont know how to put data to each file from the main file,according to the file no.and their corresponding sequence.
plz help
Nov 21 '07 #1
2 1210
971 Recognized Expert Contributor
Can you provide some actual data? Also, how is this data stored in the file, is it on one line or over multiple lines? What is separating the data?

Nov 21 '07 #2
4,059 Recognized Expert Specialist
personally I would like to see more effort on your part next time. This code is only tested with the sample data provided, may perform diferrently with real data:

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2. use strict;
  3. use warnings;
  4. open(FH,"h.txt")or die "cant open file: $!";
  5. MAINLOOP: while (<FH>) {
  6.     if (/^(AB:\d+)/) {
  7.         chomp;
  8.         tr/:/-/d;# because : should not be in filenames I change it to -
  9.         open(FHO,">", $_) or die "Can't create file $_: $!";
  10.         while (<FH>) {
  11.             if (/^(AB:\d+)/) {
  12.                 close FHO; 
  13.                 redo MAINLOOP;
  14.             }
  15.             print FHO;
  16.         }
  17.     }
  18. }                   
  19. close FH;
  20. print "finished";
Nov 21 '07 #3

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

Similar topics

by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential problem. The program may crash unexpectedly while writing to the file. If so, my program should detect this during startup, and then (during...
by: Pierre Rouleau | last post by:
Hi all! I'm trying to extend the functionality of the file object by creating a class that derives from file. MyFile class re-implements __init__(), write(), writelines() and close() to augment the capabilities of file. All works fine, except for one thing: 'print >> myfile' does not execute Myfile.write(), it executes the...
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out | ios::binary) to declare a file object with read/write modes turned on for working with binary data. I've tried this and my file is not created. The only...
by: Stewart | last post by:
is there any way this can be done? I've looked at the help files and checked out as many tutorials as i could find on the net (as always) but no joy. thanks
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile = tmpfile(); /* write into tmpFile */ ...
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
by: Doug | last post by:
Hi, It looks like the only way to get a size of a file within csharp is to use FileInfo and the Length property. However that only returns the number of bytes in the file which is translating properly (I have a file that has a size of 1 KB but has 14 bytes in it so the conversion isn't working right). Is there some method/property out...
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given by df -k lopgod10:~/mycrfile # df -k /mnt/mvdg1/vset Filesystem 1K-blocks Used Available Use% Mounted on
by: brook | last post by:
hey all - i´m new to php and having trouble writing a simple code which should create a file. here is the most simplified version: <?php $content = "my content"; $path = "test.txt"; if(!chmod($path, 0744)) { echo "error, $path"; exit; } else {
by: glennanthonyb | last post by:
Hi The company I work for has finally woken up to data security on our field laptops. I'm writing something in C# that will allow remote deletion of sensitive data and I don't believe File.Delete() will be sufficient. Is there anything in .NET that removes any remanence of the file? If it isn't going to be easy, does anyone know of a...
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...
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. ...
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...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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...
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...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.