?
Solved

two separate files combined into one by columns

Posted on 2003-03-31
9
Medium Priority
?
181 Views
Last Modified: 2011-04-14
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
Comment
Question by:scramj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 100 total points
ID: 8243537
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
 
LVL 14

Expert Comment

by:chris_calabrese
ID: 8246204
Paste will generally work, but won't match up the timestamps.
Instead use 'join'. You'll also have to 'sort' the files first.
0
 

Expert Comment

by:Jeff_Neill
ID: 8253334
You can use the "cat" command for the first part of your question.
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Expert Comment

by:Jeff_Neill
ID: 8253348
Sorry misread the first part. "cat" probably isn't what you want.
0
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 100 total points
ID: 8323067
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
 
LVL 2

Expert Comment

by:TheWeakestLink
ID: 8583897
Hi,

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question