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

Assembling small files in a large file but format is shifted

Hi Perl Experts:
I am relatively new to perl and did try to solve the problem by searching books and web but could not exactly solve it. Here is the problem. I want to gather "*.igf" files and put all the lines from these files in a larger file. However, each small file has a header on the first line. I want header only once in a bigger file. My current code does everything fine except content from file other than first file is shifted and it shifts the format. My question is how to discard first header line except when it is the first file but still maintain the format. Below is the code.

Thank you for your help.
DeepNik
Expand|Select|Wrap|Line Numbers
  1. my @igf_files = glob("*.igf");
  2. my $all_igf = "all_igf.igf";
  3. my $counter = 0;
  4. foreach my $fileigf (@igf_files) {
  5. if ($counter==0){
  6. open (IGF,"<$fileigf");
  7.     open (ALLIGF,"+>>$all_igf");
  8.     while(<IGF>)
  9.     {
  10.      print ALLIGF $_;
  11.     }
  12. close (IGF  );
  13. close ( ALLIGF );
  14. $counter++;
  15. }
  16. else{
  17. open (IGF,"<$fileigf");
  18. my @lines =(<IGF>);
  19. open (ALLIGF,"+>>$all_igf");
  20.  
  21.     {
  22.     print ALLIGF @lines[1..$#lines];
  23.      }
  24. close (IGF);
  25. close ( ALLIGF );
  26. }
  27. }
  28.  
Feb 11 '10 #1
5 1674
RonB
589 Expert Mod 512MB
Use the shift function to remove the first filename off of the array and assign it to a scalar.

Process that file, then start your loop over the remaining files.
Feb 11 '10 #2
Thank you Ron for your reply. However, yes, I can get the same functionality with shift operator but the formatting is still shifted. In the sense, content from the second small file is shifted by one space.

DeepNik
Feb 12 '10 #3
RonB
589 Expert Mod 512MB
In what way is it shifted by 1 space?

Do you end up with a single space between the contents of file1 and file2?
Do you end up with a single space between between file2 and file3?
Do you end up with a single space between each and every file?

Or, does it shift the other way by stripping off 1 character?

Can you attach a couple sample files so I can test and duplicate your issue?
Feb 12 '10 #4
RonB
589 Expert Mod 512MB
You should open the $all_igf file only once. Open it prior to opening the other files and keep it open until all files have been processed.
Feb 12 '10 #5
Hi Ron:
Thanks for sharing possibilities. It seems to me first, I should look into the way files were created. I create these files using a function and then process them. I am going to look into the way files are created. If I am unable to figure it out even after manipulating function, I will surely post sample files.

Best,
DeepNik
Feb 12 '10 #6

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

Similar topics

4
by: Dag Sunde | last post by:
Just wondering if anyone have looked into this? How to split up ones JavaScript library? A lot of very specific (and small) .js files, or a few larger files. I'm thinking about load-time...
2
by: marco.avidano | last post by:
I'm asking: for the PHP parser, it's better to create one large file with all the code inside or a lot of small files? Can a large file slow down the execution of the script?
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
0
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
2
by: jdev8080 | last post by:
We are looking at creating large XML files containing binary data (encoded as base64) and passing them to transformers that will parse and transform the data into different formats. Basically,...
31
by: JAKE | last post by:
I'm pretty new to ansi c and I'm stuck I'm trying to assemble a string in a called function. I need to send it three different data types and return the assembled string. I've been getting errors...
18
by: gonzlobo | last post by:
No, I don't want to destroy them (funny how the word 'decimate' has changed definition over the years) :). We have a data acquisition program that saves its output to Excel's ..xls format....
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
9
by: drhowarddrfine | last post by:
I don't want to use a db manager, like mysql, for such a small database but I'm finding this trickier than I thought and hope someone can provide some guidance. I have a restaurant menu with...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
1
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
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,...
0
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...

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.