LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-03-2004, 12:10 AM   #1
pantera
Member
 
Registered: May 2004
Posts: 80

Rep: Reputation: 15
merging files using perl


how can we merge 2 files using perl so that the output comes columwise not on top of tthe other .
 
Old 06-03-2004, 12:56 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
What about something like:
Code:
#!/usr/bin/perl

open(FILE,"file1");
@linesone=<FILE>;
close(FILE);
open(FILE,"file2");
@linestwo=<FILE>;
close(FILE);

if(@linesone<@linestwo){$total=@linestwo}
else{$total=@linesone}

for($line=0;$line<$total;$line++){
 chop($lineone[$line]);
 print "$lineone[$line] $linetwo[$line]";
}

exit;
I wrote that from memory but it should work. If you want to split the colum exactly in half and not just have the lines joined then add a bash escape sequence in the middle of the print statement.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging ,pdf files satimis Linux - General 6 11-21-2007 08:31 PM
merging mpg files karhu Linux - Software 4 07-28-2005 05:25 AM
merging movie files ZaphyR Linux - Software 4 09-05-2004 08:26 AM
merging arrays suing perl pantera Programming 1 06-03-2004 08:51 AM
merging log files help please digitalgravy Linux - Newbie 3 12-10-2003 02:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration