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
Shell Programming and Scripting nivas Shell Programming and Scripting 21 02-25-2008 06:27 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 2 02-20-2008 02:59 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 14 02-20-2008 02:07 AM
Shell Programming and Scripting nivas Shell Programming and Scripting 3 02-13-2008 08:10 AM
Shell scripting & programming languages aloysius1001 UNIX Desktop for Dummies Questions & Answers 1 02-19-2002 12:04 AM

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-19-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
Shell Programming and Scripting

Hi,

Iam having the files as follows:

file1
aa
aa
aa
aa
ab
ac
ad
ae

file2
aa
aa
ab

Outputfile:
aa
aa

Actually i want to track the file1 and file2 for common records.

output file should get the records that are in file1 and not in file2. Here 4 aa's are there in file1. and 2 aa's are in file2. i jus want to get " 2 aa's in file1 and 4 aa's in file2. so we need to track this aa." like this message should come in the o/p file.



Can anybody help??
  #2 (permalink)  
Old 02-19-2008
manikantants manikantants is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 131
Quote:
Originally Posted by nivas View Post
i jus want to get " 2 aa's in file1 and 4 aa's in file2. so we need to track this aa." like this message should come in the o/p file.
It should be " 2 aa's in file2 and 4 aa's in file1. so we need to track this aa.". Isn't it ?

And if you need such a message in the o/p file, awk will help you.
  #3 (permalink)  
Old 02-19-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
i don't want any messages in o/p file. i just want to tract those records that occur in file1 and file2 more than once.

pls give the help
  #4 (permalink)  
Old 02-19-2008
manikantants manikantants is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 131
cat file1 | uniq -c | awk '{ if ($1>1) print $2}'
  #5 (permalink)  
Old 02-19-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Try:
Code:
awk 'NR==FNR{a[$0]++;next}
            ( a[$0] >= 2 ){b[$0]++}
END {
for ( i in  b )
    if ( b[i] >= 2)
       print i
}' file1 file2
  #6 (permalink)  
Old 02-19-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
Quote:
Originally Posted by nivas View Post
i just want to tract those records that occur in file1 and file2 more than once.
See the difference:
Code:
> cat f1
aa
aa
aa
aa
ab
ac
ac
ad
ae
> cat f2
aa
ab
ac
ac
Code:
> paste f1 f2 |awk '{if ($1 == $2) print $1}'
aa
Or:
Code:
>awk 'NR==FNR{a[$0]++;next}
            ( a[$0] >= 2 ){b[$0]++}
END {
for ( i in  b )
    if ( b[i] >= 2)
       print i
}' f1 f2
ac
  #7 (permalink)  
Old 02-19-2008
nivas
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
This awk command is not showing any output.

awk 'NR==FNR{a[$0]++;next}
( a[$0] >= 2 ){b[$0]++}
END {
for ( i in b )
if ( b[i] >= 2)
print i
}' file1 file2
Closed Thread

Bookmarks

Tags
solaris

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 02:07 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