Teddybugs
Teddybugs

Reputation: 1244

awk invert regular expression pattern rule

i have code like this:

awk '(/\/\*\!/),(/\*\/\;/)'

that will match everything like this:

/*!40101 SET character_set_client = utf8 */;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!50001 CREATE TABLE `sometable` (
  `id` int(11),
  `name` char(30),
  `user` char(30),
) ENGINE=MyISAM */;

How can I invert the matching of my awk code above? I tried:

awk '!(/\/\*\!/),(/\*\/\;/)'
awk '!(/\/\*\!/),!(/\*\/\;/)'

Upvotes: 1

Views: 1010

Answers (2)

Kevin
Kevin

Reputation: 56089

Use a variable

awk '/\/\*!/{a=1}!a;/\*\/;/{a=0}' test.in

A couple other notes:

  • You don't need the parentheses
  • You don't need to escape ! or ;

Upvotes: 3

SaltyEgg
SaltyEgg

Reputation: 1558

Use

awk '(/\/\*\!/),(/\*\/\;/){next}{print}'

Upvotes: 1

Related Questions