![]() |
|
|
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 |
| while loop not taking the not equal to condition | ssuresh1999 | UNIX for Dummies Questions & Answers | 9 | 08-12-2008 10:05 AM |
| Edit entry if not equal | kenshinhimura | Shell Programming and Scripting | 4 | 08-07-2008 12:18 AM |
| Stop+A equal | tlee | SUN Solaris | 5 | 07-01-2008 07:42 AM |
| add not equal in script. | myguess21 | Shell Programming and Scripting | 2 | 02-26-2008 10:20 AM |
| Making a variable equal a pattern | Bab00shka | UNIX for Dummies Questions & Answers | 3 | 03-08-2004 06:46 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
awk check for equal - help
Input file: Code:
x A 10 y A 10 z A 10 x B 10 y B 12 z B 10 x C 0 y C 0 Required output: Code:
x B 10 y B 12 z B 10 i.e. printing only that section (based on 2nd field) for which third field($3) is not equal for all the lines for that 2nd field. Please help |
|
|||||
|
It's easy to produce the desired ouput but I didn't understand your explanaton. Quote:
![]() If so... Code:
grep " B " infile| uniq |
|
||||
|
Thanks Zaxxon and vgersh99 for the reply. I want to only print the section for which 3rd field is different (one section is basically based on second field, here A,B and C ). Code:
x A 10 y A 10 z A 10 x B 10 y B 12 z B 10 x C 0 y C 0 |
|
||||
|
Code:
x B 10 y B 12 z B 10 for A, all the third fields are same (10), same for C(0), but for B the 3rd fields are not same, so I wanted to print B section. |
|
||||
|
hi , seems perl is a little bit eaiser to handle Code:
#!/usr/bin/perl
use strict;
my (%hash,%h);
open FH,"<a";
while(<FH>){
my @tmp=split(" ",$_);
$hash{$tmp[1]}.=$_;
$h{$tmp[1]}->{$tmp[2]}=1;
}
close FH;
for my $key (sort keys %hash){
my @tmp=keys %{$h{$key}};
print $hash{$key} if $#tmp>=1;
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|