Skip to main content
IFS is for shell. FS is for Awk.
Source Link
Wildcard
  • 37.5k
  • 30
  • 149
  • 284
awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input 

To expand the script vertically for explanation:

BEGIN { IFS="FS="," # Set the input separator; this is what -F, does. } $2 == "false" { # For any line whose second field is "false", we data[$1]=$2 # will use that value no matter what. } $2=="true" { # For lines whose second field is "true", if ( data[$1]!="false" ) { # only keep if if we haven't yet seen a data[$1]=$2 # "false" } } END { # Now that we have tabulated our data, we OFS="," # can print it out by iterating through for (item in data) { # the array we created. print item,data[item] } } 
awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input 

To expand the script vertically for explanation:

BEGIN { IFS="," # Set the input separator; this is what -F, does. } $2 == "false" { # For any line whose second field is "false", we data[$1]=$2 # will use that value no matter what. } $2=="true" { # For lines whose second field is "true", if ( data[$1]!="false" ) { # only keep if if we haven't yet seen a data[$1]=$2 # "false" } } END { # Now that we have tabulated our data, we OFS="," # can print it out by iterating through for (item in data) { # the array we created. print item,data[item] } } 
awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input 

To expand the script vertically for explanation:

BEGIN { FS="," # Set the input separator; this is what -F, does. } $2 == "false" { # For any line whose second field is "false", we data[$1]=$2 # will use that value no matter what. } $2=="true" { # For lines whose second field is "true", if ( data[$1]!="false" ) { # only keep if if we haven't yet seen a data[$1]=$2 # "false" } } END { # Now that we have tabulated our data, we OFS="," # can print it out by iterating through for (item in data) { # the array we created. print item,data[item] } } 
added 778 characters in body
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141
awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input 

To expand the script vertically for explanation:

BEGIN { IFS="," # Set the input separator; this is what -F, does. } $2 == "false" { # For any line whose second field is "false", we data[$1]=$2 # will use that value no matter what. } $2=="true" { # For lines whose second field is "true", if ( data[$1]!="false" ) { # only keep if if we haven't yet seen a data[$1]=$2 # "false" } } END { # Now that we have tabulated our data, we OFS="," # can print it out by iterating through for (item in data) { # the array we created. print item,data[item] } } 
awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input 
awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input 

To expand the script vertically for explanation:

BEGIN { IFS="," # Set the input separator; this is what -F, does. } $2 == "false" { # For any line whose second field is "false", we data[$1]=$2 # will use that value no matter what. } $2=="true" { # For lines whose second field is "true", if ( data[$1]!="false" ) { # only keep if if we haven't yet seen a data[$1]=$2 # "false" } } END { # Now that we have tabulated our data, we OFS="," # can print it out by iterating through for (item in data) { # the array we created. print item,data[item] } } 
Source Link
DopeGhoti
  • 79.2k
  • 10
  • 107
  • 141

awk -F, '$2 == "false" {data[$1]=$2 } $2=="true" { if ( data[$1]!="false" ) { data[$1]=$2 } } END { OFS=","; for (item in data) { print item,data[item] }}' input