The UNIX and Linux Forums  


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
selection of files based on its types ganapati UNIX for Advanced & Expert Users 3 02-04-2008 10:09 AM
copy diff files Hitori UNIX for Advanced & Expert Users 3 07-15-2006 07:53 AM
searching text files on specific columns for duplicates Gerry405 UNIX for Dummies Questions & Answers 2 08-18-2005 11:51 AM
find directory with 2 types of files dangral UNIX for Dummies Questions & Answers 2 10-13-2004 02:51 PM
diff 2 files; output diff's to 3rd file blt123 Shell Programming and Scripting 2 05-28-2002 12:29 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-04-2008
ricky007 ricky007 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 9
Smile Find duplicates from multuple files with 2 diff types of files

I need to compare 2 diff type of files and find out the duplicate after comparing each types of files:

Type 1 file name is like: file1.abc
(the extension abc could any 3 characters but I can narrow it down or hardcode for 10/15 combinations).

The other file is file1.bcd01abc (the extension bcd is constant, 2 digit (00 to 04) and last three character could be any 3 letters (I can narrow that last 3 charcaters to 10-15 combinations).

whenever the script finds a duplicate after coparing these two types of files, the output will indicate "duplicate found in file1.abc and and file1.bcd01abc and the value is xxxx".


Both of file format:
172.10.10.19<TAB>rou020i00sfg<TAB>descriptions

Thanks and this is not a homwork.
  #2 (permalink)  
Old 03-04-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,790
This finds duplicates

Code:
find_dup()
{
awk ' FILENAME=="file1" { arr[$0]++ }
        FILENAME=="file2" { if (arr[$0] { print "value is", $0} }
      ' file1 file2
}

Write a loop that generates one set of filenames - the file1.abc things put it into a file -dirfile1
get another list of the other type of files - call the file dirfile2

Okay now call the find_dup() fuunction for each file combination:

Code:
#/bin/ksh
while read file2 
do
   while read file1 
   do
        ln -s file1 $file1
        ln -s file2 $file2
        result=$( find_dup )
        if [[ ! -z $result ]] ; then
           echo "duplicate found in $file1 and $file2 $result"
        fi
   done  < dirfile1
done < dirfile2  > result.log

result.log will have what you found.
  #3 (permalink)  
Old 03-04-2008
ricky007 ricky007 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 9
How do I differentiate file name extensions.
see both file nane starts with file1, but the extensions are diff.
file1.xxx
file1.bcd00xxx

so while read should I put file1.*
and then second file file1.bcd*

also I am getting error:

[13]: dirfile2: cannot open

Thanks

Last edited by ricky007; 03-05-2008 at 12:40 PM..
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 12:41 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