awk check for equal - help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk check for equal - help
# 1  
Old 02-24-2009
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
# 2  
Old 02-24-2009
Quote:
Originally Posted by uwork72
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  
Old 02-24-2009
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? Smilie
If so...

Code:
grep " B " infile| uniq

# 4  
Old 02-24-2009
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  
Old 02-24-2009
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  
Old 02-24-2009
Quote:
Originally Posted by uwork72
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  
Old 02-24-2009
Quote:
Originally Posted by vgersh99
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

awk not equal

Did I do something wrong with this awk not equal? For some reason it prints twice. >awk '{if ($4 != "root") print $1 " " $4 " " $5}' ls_test server10: njs nodeadm server10: njs nodeadm >grep server10 ls_test server10: drwxr-sr-x. 18 njs nodeadm 4096 Aug 16 09:42 /opt > (2 Replies)
Discussion started by: cokedude
2 Replies

2. Shell Programming and Scripting

awk to print record not equal specific pattern

how to use "awk" to print any record has pattern not equal ? for example my file has 5 records & I need to get all lines which $1=10 or 20 , $2=10 or 20 and $3 greater than "130302" as it shown : 10 20 1303252348212B030 20 10 1303242348212B030 40 34 1303252348212B030 10 20 ... (14 Replies)
Discussion started by: arm
14 Replies

3. Shell Programming and Scripting

AWK splitting a string of equal parts of 500 chars

Hi , can someone help me how to make an AWK code for splitting a string of equal parts of 500 chars in while loop? Thank you! (4 Replies)
Discussion started by: sanantonio7777
4 Replies

4. Shell Programming and Scripting

HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ?

Hello experts, I'm stuck with this script for three days now. Here's what i need. I need to split a large delimited (,) file into 2 files based on the value present in the last field. Samp: Something.csv bca,adc,asdf,123,12C bca,adc,asdf,123,13C def,adc,asdf,123,12A I need this split... (6 Replies)
Discussion started by: shell_boy23
6 Replies

5. Shell Programming and Scripting

Using awk, print all the lines where field 8 is equal to x

Using awk, print all the lines where field 8 is equal to x I really did try, but this awk thing is really hard to figure out. file1.txt"Georgia","Atlanta","2011-11-02","x","","","","" "California","Los Angeles","2011-11-03","x","","","",""... (2 Replies)
Discussion started by: charles33
2 Replies

6. Shell Programming and Scripting

awk - setting fs to equal any single character

Hi Does anyone know how to set any character as the field separator with awk/nawk on a solaris 10 box. I have tried using /./ regex but this doesnt work either and im out of ideas. thanks (7 Replies)
Discussion started by: chronics
7 Replies

7. Shell Programming and Scripting

awk script replace positions if certain positions equal prescribed value

I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX. awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies

8. Shell Programming and Scripting

awk field equal something, then add something to the field

Hi Everyone, a.txt a b c 1 e e e e e a b c 2 e e e e e the output is a b c 1 e e e e e a 00b c 2 e e e e e when 4th field = '2', then add '00' in the front of 2nd field value. Thanks (9 Replies)
Discussion started by: jimmy_y
9 Replies

9. Shell Programming and Scripting

while [ $x -ge 50 ] + and equal to zero ; then

while + and equal to zero ; then what to punt instead of phrase and equal to zero. it's bash thank you in advance (1 Reply)
Discussion started by: losh
1 Replies
Login or Register to Ask a Question