![]() |
|
|
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 |
| Find top N values for field X based on field Y's value | FrancoisCN | Shell Programming and Scripting | 1 | 05-29-2009 10:57 AM |
| How to compare a field value of a same column? | gobinath | Shell Programming and Scripting | 6 | 05-06-2009 02:39 AM |
| Compare two arrays in sh or compare two fields | rijeshpp | Shell Programming and Scripting | 0 | 10-31-2007 02:47 AM |
| Compare dates in a field and print the latest date row | cvkishore | Shell Programming and Scripting | 1 | 08-04-2007 08:58 AM |
| Moving Part of a field to another field using AWK | rjsha1 | Shell Programming and Scripting | 5 | 08-04-2006 06:39 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
compare second field
Hi,
I have two files, mentioning below 1st file: 919030055000,1 919030055000,3 919030055000,7 919030155000,1 919030155000,3 919031055000,1 919031055000,8 919031155000,1 919031155000,8 919036055000,3 919036055000,7 919036155000,3 919036155000,7 919040055000,1 919040055005,7 919045123243,13 2nd file: 919030,1 919031,8 919036,3 919040,7 919045,13 I need to compare 2nd field of each entry in 1st file with the 2nd field of 2nd file with corresponding entry. Kindly suggest me any command or something else in Unix. Result required : COUNT for both fields matchs = 5 Thanks for support. |
|
||||
|
I have to count the matches field from both files:
matching fields from 1st file are: 919030055000,1 919031055000,8 919036055000,3 919040055000,7 919045123243,13 corresponded to 2nd file entry. Hence count is 5. Thanks for your kind attention. |
|
||||
|
Still not proper .. Code:
919030055000,1 919031055000,8 919036055000,3 919040055000,7 919045123243,13 corresponded to 2nd file entry. Where as your second file contains : Code:
2nd file: 919030,1 919031,8 919036,3 919040,7 919045,13 where the match is happening ?... Y not Code:
919030155000,1
919031155000,8
...........
.......
From the First file ?... |
|
||||
|
I have to count the matches field from both files:
matching fields from 1st file are: 919030055000,1 919030055000,3 919030055000,7 919030155000,1 919030155000,3 919031055000,1 919031055000,8 919031155000,1 919031155000,8 919036055000,3 919036055000,7 919036155000,3 919036155000,7 919040055000,1 919040055005,7 919045123243,13 corresponded to 2nd file entry. 919030,1 919031,8 919036,3 919040,7 919045,13 result is 919030055000,1 919031055000,8 919036055000,3 919040055000,7 919045123243,13 Count=5 i did work : cat Second_FILE.txt | while read myLine do myWord1=`echo $myLine|awk -F "," '{print $1}'` myWord2=`echo $myLine|awk -F "," '{print $2}'` myWord4=`grep ^$myWord1 FIRST.txt | awk -F "," '{print $2}'` ################### Comparing 2nd field of 1st file with 2nd file ############## if [ $myWord2 -eq $myWord4 ];then hplmn=`expr $hplmn + 1` echo $hplmn >> NUMBER.txt fi echo "COUNT for both fields matchs =" $hplmn done But it is not work properly; |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|