473,657 Members | 2,449 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=

AB:110256
aattggcaatgc
AB:1569854
ttgcttgcaa
aatcgcttttaa
ttttaaatgc
AB:569587
atgccttcat
cctcggattaag

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:

ttgcttgcaa
aatcgcttttaa
ttttaaatgc

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. ..
  2.  
  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.                  }
  9.  
  10. close FH;
  11. close FHO;
  12.  
  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 1221
eWish
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?

--Kevin
Nov 21 '07 #2
KevinADC
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

48
8469
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 startup) probably delete the data added to the file and redo the writing operation.
2
1348
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 file.write(). If I execute myfile.write() explicitly, then Myfile.write() is called as expected.
8
9845
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 time it is created is when I specify ifstream or ofstream but not fstream. I've tried removing the...
8
3287
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
4
9823
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 */ ...
3
26259
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
4
3663
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 there that will get the actual size of the file? Also, would there be a method like this that will...
14
2799
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
3
2048
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 {
12
4708
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 component that I can hook into to do the dirty work, free of otherwise?
0
8395
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
8826
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
8732
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
8605
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...
1
6166
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
5632
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
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1615
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.