-1

In an awk program , I'm trying to select the input from a line containing <<<local>>> and the next line containing the pattern <<<XXXX>>>, where XXXX will be anything else but local.

<<<local>>>
line1
line2
line3
<<<XXXX>>>

The simplest awk code would be

$0=="<<<local>>>",/^<<<XXXX>>>$/ { ··· }

but XXXX should be replaced with a proper regular expression to exclude local.

As far I know, that can be done in python

(?!local)

and in Korn shell and other shells:

!(local)

but I have found nothing about this issue in the regex(7) man pages.

In order to bypass this handicap I use

$0=="<<<local>>>",/^<<<.+>>>$/ && $0!="<<<local>>>" { ··· }

but the crux of this question of mine is wether the awk regex engine accepts somehow a word list to exclude, I mean, as a counterpart of word1|word2|word3.

Jdamian
  • 3,015
  • 2
  • 17
  • 22
  • 3
    While the information is helpful. Can you give an actual example input and an expected output needed to help us understand bette – Inian Jan 18 '18 at 08:27
  • 2
    Even `line1` will also satisfy negative lookahead that is `(?!local)` – anubhava Jan 18 '18 at 08:35
  • example of input/output please – Allan Jan 18 '18 at 08:50
  • 1
    awk doesn't support lookarounds.. and I'd suggest to use flags(https://stackoverflow.com/questions/38972736/how-to-select-lines-between-two-patterns/) instead of `//,//` syntax... – Sundeep Jan 18 '18 at 09:02
  • @Inian@Allan I do not want you to provide me an awk code. Actually I want you to answer what I asked in the two last lines of my question. – Jdamian Jan 18 '18 at 10:26
  • 1
    It sure does provide. You can do `!/word1/ && !/word2/ && !/word3/` – anubhava Jan 18 '18 at 10:31

1 Answers1

0

this would do...

awk '/<<<local>>>/{f=1} f; /<<<.*>>>/ && !/<<<local>>>/{f=0}' file

if you don't want to terminate the range for another word you can add to !/<<<(local|other)>>>/

karakfa
  • 66,216
  • 7
  • 41
  • 56