regex - decipher the regular expression -
please me decipher regular expression-
'!_[$0]++'
it being used msisdn (one @ time file containing list of msisdn starting 0 )by following usage:
awk '!_[$0]++' file.txt
it's not regular expression, it's arithmetic , boolean expression.
$0
= current input line_[$0]
= associative array element key input line_[$0]++
= increment array element each time encounter repeat of line, evaluates original value!_[$0]++
= boolean inverse, returns true if value 0 or empty string, false otherwise
so expression true first time line encountered, false every other time. since there's no action block after expression, default print line if expression true, skip when false.
so prints input file duplicates omitted.
Comments
Post a Comment