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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-24-2009
Registered User
 

Join Date: Aug 2008
Posts: 32
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
Sponsored Links
  #2 (permalink)  
Old 02-24-2009
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,200
Quote:
Originally Posted by uwork72 View Post
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
Hmm..... this is a bit confusing...
why do you have records in red then?

Code:
x B 10
y B 12
z B 10

Could you rephrase the description, please.
  #3 (permalink)  
Old 02-24-2009
zaxxon's Avatar
zaxxon zaxxon is online now Forum Staff  
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 2,668
It's easy to produce the desired ouput but I didn't understand your explanaton.

Quote:
for which third field($3) is not equal for all the lines for that 2nd field
So you want those having $2 == B and also the whole line being unique?
If so...


Code:
grep " B " infile| uniq

  #4 (permalink)  
Old 02-24-2009
Registered User
 

Join Date: Aug 2008
Posts: 32
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

  #5 (permalink)  
Old 02-24-2009
Registered User
 

Join Date: Feb 2009
Location: India
Posts: 45
To: UnWork72
The replies you have been recived are really for that you have actually asked???

coz i feel you are not specific about "B" in column 2, i mean $2

What i feel is it depends on column 2 but you have to find unmatched in column 3,
m i rite???

if yes.... can we work out n discuss
  #6 (permalink)  
Old 02-24-2009
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,200
Quote:
Originally Posted by uwork72 View Post
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

ok, so what the output of the above?
  #7 (permalink)  
Old 02-24-2009
Registered User
 

Join Date: Aug 2008
Posts: 32
Quote:
Originally Posted by vgersh99 View Post
ok, so what the output of the above?

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.
Sponsored Links
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 Off


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 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



All times are GMT -4. The time now is 10:51 AM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0