Reputation: 717
I'm having a bit of a problem trying to select specific lines of data in awk. I want data the starts with FWA20120629, then has 4 numbers I don't care about, then has and 18,19,or 20, and then two more characters I don't care about. I've tried this:
awk '{if ($2 ~ /FWA20120629....[18-20]../) print $2,$5,$6}' ...
and
awk '{if ($2 ~ /FWA20120629????[18-20]??/) print $2,$5,$6}' ...
an example line that would fit this criteria is
FWA2012062903001800
I'm clearly missing something, and I'm not familiar enough with awk to figure it out.
Upvotes: 0
Views: 1306
Reputation: 206909
[...]
are character classes in regular expressions. [18-20]
doesn't match all numbers between 18 and 20, it matches the character 1, all characters between 8 and 2 (which is meaningless), and the character 0.
Try (18|19|20)
instead if that's what you want.
Upvotes: 3