The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-11-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
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
The above is a single line in file2. there are many lines like this.

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.
  #2 (permalink)  
Old 02-11-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
if the line in file1 matches the first column in file2, why would you need to paste it to file2? It's already in file2.
  #3 (permalink)  
Old 02-11-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
shell programming

Sorry ....I am over confused about this issue.

If the file 1 is matching with the file2 column 1, then i need to select that row alone and write it in to new file.

That;s it.


Thanks for your valuble time.
  #4 (permalink)  
Old 02-11-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
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;
  #5 (permalink)  
Old 02-11-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
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.
  #6 (permalink)  
Old 02-11-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
shell programming

Thanks for your time, and solution.


But ineed solution in shell program, ...i dion't know perl.sorry for that
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0