Re: Merge part of CSV files



sparrie2k wrote:
Hi,
I'm trying to merge some CSV files into one. They all have a header
line, a single data line and footer line, but it is only the data line
(minus the first field) that I want to merge. The bit I'm missing-out
from the data line is a line number (always 001 in the single files) so
I'll be doing an incremental count in the combined file. The header and
footer lines are not required at all.
Has anyone got any ideas on a quick and easy way to do this?

One way to do this is to write a script that will open each file in
turn, delete all the lines that match your header and footer, and
append whatever is left to the master file. If you want line numbers,
just add a counter that increments once per loop, and concatinate the
counter to your line of text just before you append it.

You can either pass the script a list containing all the file names, or
place all the files into a deparate directory and iterate through all
the files in that directory.

Your algorithm would look something like this:

open OUTFILE for appending
while infiles
open INFILE for reading
remove header line
remove footer line
print OUTFILE counter, line
close OUTFILE
increment counter
close OUTFILE
exit

CC

.



Relevant Pages

  • Re: Perl script to clean up file -- Dont know if it can be done
    ... > has a header and footer, as well as page breaks, this is all in ASCII ... stuff and doing the transformation). ... my $outfile = 'outfile'; ...
    (comp.lang.perl.misc)
  • Re: Merge part of CSV files
    ... They all have a header ... line, a single data line and footer line, but it is only the data line ... footer lines are not required at all. ... Why do the poets of the present not speak of it? ...
    (comp.lang.perl.misc)
  • Re: Splitting huge XML Files into fixsized wellformed parts
    ... Copy Header and Footer from Original to Var ... print header> outfile ...
    (comp.lang.awk)
  • Re: Merge part of CSV files
    ... I'm trying to merge some CSV files into one. ... They all have a header ... line, a single data line and footer line, but it is only the data line ... footer lines are not required at all. ...
    (comp.lang.perl.misc)
  • Merge part of CSV files
    ... I'm trying to merge some CSV files into one. ... They all have a header ... line, a single data line and footer line, but it is only the data line ... footer lines are not required at all. ...
    (comp.lang.perl.misc)