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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -