Thursday 23 November 2017

awk + one line awk syntax to print only once the second field if "true" word matched

itemprop="text">

I don't know how to do this with
awk
But my target is to create awk one line syntax in order to print the
second field ($2) if
all first field ($1) are true




for
example



I have the
file:



 true
my_name_is_lenon
true my_name_is_lenon
true
my_name_is_lenon
false my_name_is_lenon
true
my_name_is_lenon


false my_dog_is_fat
true
my_dog_is_fat
true my_dog_is_fat

true
I_am_very_tall
true I_am_very_tall
true
I_am_very_tall

true my_ball_is_fine
true
my_ball_is_fine



the
awk will print only the
following:




I_am_very_tall

my_ball_is_fine


Because
I_am_very_tall , my_ball_is_fine get true on the first field without
false




my_dog_is_fat ,
my_name_is_lenon not printed because the false word on the first
field



The rule is to print the second field if
no false word on the first field! (Of all the same sentence on the second
field)



lidia



Answer




Here is one
way:



awk '{if ($1 == "false")
{array[$2] = $1} else if (array[$2] != "false") array[$2] = $1} END {for (i in array) if
(array[i] == "true") print i}'
inputfile



Edit:



Here
it is on multiple lines:



awk '{if
($1 == "false")
{array[$2] = $1}
else if (array[$2] != "false")

array[$2] = $1}
END {for (i in array)

if
(array[i] == "true")
print i}
'
inputfile

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...