1835104 Members
2467 Online
110076 Solutions
New Discussion

combine records in files

 
SOLVED
Go to solution
Thomas Buck_1
New Member

combine records in files

Hi all,
I have two data files. I need to merge the records, but cannot figure out how to do this. I have discovered numerous ways to append fileA to fileB, but the records need to be merged.
Example

FileA has records:
This is a
And so is
This one is

FileB has records:
long record
this record
longer now

I need a third file, FILEC which would look like this:
This is a long record
And so is this record
This one is longer now

Does anyone know of a way to do this? I am fairly new to HP-UX and am tired of pulling my hair out!
Thanks in advance!
4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: combine records in files

paste FileA FileB > FILEC

man paste for details.

If it ain't broke, I can fix that.
Jeff Schussele
Honored Contributor

Re: combine records in files

Hi,

You get a little more format control with

pr -t -m FILEA FILEB > FILEC

man pr for details.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Elena Leontieva
Esteemed Contributor

Re: combine records in files

Or you can do it in a shell script:

merge.sh f1 f2,

where merge.sh looks like below and your merged file will be f3:

#!/bin/ksh
while read -u3 f1 && read -u4 f2; do
print "$f1" "$f2" >> f3
done 3<$1 4<$2

HTH,
Elena.
Thomas Buck_1
New Member

Re: combine records in files

Thank you all for the great answers, my problem is solved.

In this particular case, the paste command worked perfectly, but I am printing out all the other solutions for future reference.