![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 |
| need help for shell programming | thungmail | Shell Programming and Scripting | 3 | 04-02-2008 03:55 PM |
| Aix Shell Programming | akmtcs | AIX | 1 | 12-07-2006 08:40 AM |
| shell programming | Neha Agarwal | Shell Programming and Scripting | 2 | 09-07-2005 02:23 AM |
| Shell Programming Help | mec585858 | UNIX for Dummies Questions & Answers | 4 | 12-10-2003 10:24 AM |
| Shell Programming | JWK1 | UNIX for Dummies Questions & Answers | 2 | 06-01-2001 01:31 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
shell programming
Hi iam new to shell programming. I would like to ask one dought abt the file
handling in unix. Iam having a file1 as follows: ASDERFCX1234567890123456 POIUYTRE0098765432123456 BVCXCVBN0955644411111111 File2 Code:
ASDERFCX1234567890123456 kill@abc.com 2008-02-020005009.55 0000000 00100.00 2008-03-01 JILL,POWER J 000000000000006.16 000000000000000.00 CBB00010000000911 So i need to check compare the file1 with file2(1st column). If that info matches in file 2 then i need to paste file 1 in file2 1st column and othe other coulumn in file2 should remain same without any space modifications. Most important is records present in file 1 should be there in file2 and other lines in file 2 should be deleted in file2. Please give me the soulution to resolve this problem. Thanks in advance. |
|
||||
|
I only know perl well enough to do this:
Code:
#!/usr/bin/perl
use warnings;
use strict;
my %file2;
open (FILE2, '<' , 'path/to/file2') or die "$!";
while(<FILE2>){
$file2{(split(/\s+/))[0]}=1;
}
close FILE2;
open (FILE1, '<' , 'path/to/file1') or die "$!";
open (OUT, '>' , 'path/to/outputfile') or die "$!";
while(<FILE1>){
chomp;
if (exists $file2{$_}) {
print OUT "$_\n";
}
}
close FILE1;
close OUT;
|
|
||||
|
You want to read the smaller of the two files into a hash, so if file1 is considerbaly smaller than file2, file1 should be read into a hash to compare to file2 instead of how I did it. If both files are the same or nearly the same size it does not matter.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|