|
Home > Archive > Unix Shell > February 2007 > merge files along with file names
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
merge files along with file names
|
|
|
| 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.
| |
| Bill Marcum 2007-02-15, 7:15 pm |
| On 15 Feb 2007 11:57:52 -0800, vp
<vijay_dwi@yahoo.com> wrote:
>
>
> 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.
>
awk 'FNR==1{split(FILENAME,part,".")} {print part[2], $0}' xxx*dat > XXX.dat
As usual, if you use Solaris, use nawk or /usr/xpg4/bin/awk, not the old
broken awk.
--
"It's not just a computer -- it's your XXX."
-- Cal Keegan
|
|
|
|
|