• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

two separate files combined into one by columns

This one may be easy:
I have two files, each containing a single list. I would like to combine these lists one space apart in a single file. Is there a method I can do this in using perl, bourne or bash?

Slightly harder question:
 I have two files, one containing a single timestamp list:

10:00:32
10:00:35
10:00:48
The other contains variable length data with a fixed text mark:

cam1-MSG this is a test
cam1-MSG this is a test 2
cam1-MSG this is a new test

I would like to combine these two files with the following result:

10:00:32 cam1-MSG this is a test
10:00:35 cam1-MSG this is a test 2
10:00:48 cam1-MSG this is a new test

Any suggestions or ideas? Better yet, any known scripts that might already be able to do this? Thanks!
0
scramj
Asked:
scramj
2 Solutions
 
yuzhCommented:
use "paste" command to do the job:

eg: file A:
10:00:32
10:00:35
10:00:48

    file: B
cam1-MSG this is a test
cam1-MSG this is a test 2
cam1-MSG this is a new test


you do:
paste A B > C

file C is the result you wanted.

man paste
to learn more details

Cheers!
0
 
chris_calabreseCommented:
Paste will generally work, but won't match up the timestamps.
Instead use 'join'. You'll also have to 'sort' the files first.
0
 
Jeff_NeillCommented:
You can use the "cat" command for the first part of your question.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jeff_NeillCommented:
Sorry misread the first part. "cat" probably isn't what you want.
0
 
FishMongerCommented:
Here's a Perl solution.  Keep in mind that with Perl, there is allways more that one way to do everything.

#!/usr/bin/perl

$src1 = "source file 1";
$src2 = "source file 2";
$dest = "destination file";

open SRC1, $src1 or die "could not open source file $src1 <$!>";
open SRC2, $src2 or die "could not open source file $src2 <$!>";
open DEST, ">$dest" or die "could not open destination file $dest <$!>";

@src1 = (<SRC1>);
@src2 = (<SRC2>);
close SRC1;
close SRC2;

chomp foreach (@src1);
for ($i = 0; $i <= $src1[-1]; $i++){
   print DEST "$src1[$i] $src2[$i]";
}
close DEST;
0
 
TheWeakestLinkCommented:
Hi,

If you want to do it manually, the freeware editor "nedit" has a wonderful rectangular cut and paste capability.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now