merge files along with file names - Aix

This is a discussion on merge files along with file names - Aix ; I have 3 flat files, have to merge those files into one file and have to append the individual sequence number from the filename to its file individual file data File Names: ============== xxx.000123.dat xxx.000124.dat xxx.000125.dat .. .. .. For ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: merge files along with file names

  1. merge files along with file names

    I have 3 flat files, have to merge those files into one file and have
    to append the individual sequence number from the filename to its file
    individual file data

    File Names:
    ==============
    xxx.000123.dat
    xxx.000124.dat
    xxx.000125.dat
    ..
    ..
    ..


    For example if File name 1: "xxx.000123.dat" has all the last names of
    10 people and file name 2:"xxx.000124.dat" has 10 Last Name, I have
    merge them into a one file XXX.dat with 20 records and and at the same
    time have the add the number from the file "000123" at the beginning
    all the 10 records and add the number from the file "000124" at the
    beginning of the other 10 records in the merged file.


  2. Re: merge files along with file names

    vp wrote:
    > I have 3 flat files, have to merge those files into one file and have
    > to append the individual sequence number from the filename to its file
    > individual file data
    >
    > File Names:
    > ==============
    > xxx.000123.dat
    > xxx.000124.dat
    > xxx.000125.dat
    > ..
    > ..
    > ..
    >
    >
    > For example if File name 1: "xxx.000123.dat" has all the last names of
    > 10 people and file name 2:"xxx.000124.dat" has 10 Last Name, I have
    > merge them into a one file XXX.dat with 20 records and and at the same
    > time have the add the number from the file "000123" at the beginning
    > all the 10 records and add the number from the file "000124" at the
    > beginning of the other 10 records in the merged file.
    >


    perl -ne '$ARGV =~ /\.(\d+)\.dat/; print "$1 $_"' xxx.*.dat > xxx.dat

    --
    Alex.

  3. Re: merge files along with file names

    On Feb 15, 11:44 am, "vp" wrote:
    > I have 3 flat files, have to merge those files into one file and have
    > to append the individual sequence number from the filename to its file
    > individual file data
    >
    > File Names:
    > ==============
    > xxx.000123.dat
    > xxx.000124.dat
    > xxx.000125.dat
    > .
    > .
    > .
    >
    > For example if File name 1: "xxx.000123.dat" has all the last names of
    > 10 people and file name 2:"xxx.000124.dat" has 10 Last Name, I have
    > merge them into a one file XXX.dat with 20 records and and at the same
    > time have the add the number from the file "000123" at the beginning
    > all the 10 records and add the number from the file "000124" at the
    > beginning of the other 10 records in the merged file.


    Better use a join command to merge common fileds in a file( use loops
    to join a number of files, if the files are less these can be directly
    specified). Use awk to add the desired fileds.
    HTH


+ Reply to Thread