![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Merge Two Files based on First column | apjneeraj | Shell Programming and Scripting | 10 | 04-13-2009 01:44 AM |
| Merge lines in Flat file based on first 5 characters | Brado | Shell Programming and Scripting | 3 | 04-06-2009 02:57 PM |
| merge rows based on a common column | smriti_shridhar | Shell Programming and Scripting | 6 | 10-17-2008 07:15 AM |
| compare the column from 3 files and merge that line | ganesh_mak | Shell Programming and Scripting | 8 | 04-14-2008 08:56 AM |
| Merge files based on key | sbasetty | Shell Programming and Scripting | 3 | 02-02-2007 06:05 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
merge two two txt files into one file based on one column
Hi,
I have file1.txt and file2.txt and would like to create file3.txt based on one column in UNIX Eg: file1.txt 17328756,0000786623.pdf,0000786623 20115537,0000793892.pdf,0000793892 file2.txt 12521_74_4.zip,0000786623.pdf 12521_15_5.zip,0000793892.pdf Desired Output file3.txt 17328756,0000786623.pdf,0000786623,12521_74_4.zip 20115537,0000793892.pdf,0000793892,12521_15_5.zip Please advice!! Last edited by techmoris; 08-20-2009 at 02:12 PM.. |
|
||||
|
Code:
#!/usr/bin/perl
use Tie::File;
use strict;
use warnings;
my $output;
tie my @file1, "Tie::File", "file1.txt";
tie my @file2, "Tie::File", "file2.txt";
foreach my $line1 (@file1) {
foreach my $line2 (@file2) {
$output = join ",", $line1,$line2;
}
open (FILE, ">>", 'file3.txt') or die "Cannot open file!\n";
print FILE "$output\n";
close FILE;
}
|
|
||||
|
Quote:
I actually have 5. file1 file2 file3 file4 file5 thanks. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|