Skip to main content
more idiomatic
Source Link
steeldriver
  • 83.9k
  • 12
  • 124
  • 175

With perl List::MoreUtils, by evaluating the distinct / uniq elements in scalar context:

perl -MList::MoreUtils=uniqMoreUtils=distinct -F, -lne ' print( (uniqdistinct @F) ==> 1 ? $F[0]"no_match" : "no_match"$F[0]) ' example  1-69 no_match 1-46 no_match 6-1 5-51 4-59 

With perl List::MoreUtils, by evaluating the uniq elements in scalar context:

perl -MList::MoreUtils=uniq -F, -lne ' print( (uniq @F) == 1 ? $F[0] : "no_match") ' example 1-69 no_match 1-46 no_match 6-1 5-51 4-59 

With perl List::MoreUtils, by evaluating the distinct / uniq elements in scalar context:

perl -MList::MoreUtils=distinct -F, -lne ' print( (distinct @F) > 1 ? "no_match" : $F[0]) ' example  1-69 no_match 1-46 no_match 6-1 5-51 4-59 
Source Link
steeldriver
  • 83.9k
  • 12
  • 124
  • 175

With perl List::MoreUtils, by evaluating the uniq elements in scalar context:

perl -MList::MoreUtils=uniq -F, -lne ' print( (uniq @F) == 1 ? $F[0] : "no_match") ' example 1-69 no_match 1-46 no_match 6-1 5-51 4-59