how to omit/ignore/remove lines starting with local/ using awk

Variable _RESULT contains an output of pacinfo --verbose local/jre.
Using awk script (by Ed Morton – thanks to him!):

awk '{
      match($0,/:[[:space:]]*/)
      nextTag = substr($0,1,RSTART-1)
      if ( nextTag != tag )
      {
              if ( NR > 1 )
              {
                      prt()
              }
              numVals = 0
              tag = nextTag
      }
      valInBeg = RSTART + RLENGTH
      vals[++numVals] = substr($0,valInBeg)
      }
      END { prt() }

      function prt(   i, pfx) {
      pfx[0] = sprintf("%-*s: ", valInBeg-1, tag)
      pfx[1] = ( vals[1] ~ /[/]|:/ ? sprintf("%s%*s", ORS, valInBeg+1, "") : OFS )
      for ( i=1; i<=numVals; i++ )
      {
      printf "%s%s%s", pfx[(i>1)], vals[i], (i<numVals ? "" : ORS)
      }
}' <<<$_RESULT

I got:

Name            : jre
Base            : jdk
Repository      : ls-aur
File            : jre-22.0.1-2-x86_64.pkg.tar.zst
Version         : 22.0.1-2
Description     : Oracle Java Runtime Environment
Architecture    : x86_64
URL             : https://www.oracle.com/java/
Licenses        : LicenseRef-custom
Provides        : java-runtime=22 java-runtime-jdk22 jre22-jdk=22.0.1-2 java-runtime-headless=22 java-runtime-headless-jdk=22 jre22-jdk-headless=22.0.1-2
Requires        : java-runtime-common ca-certificates-utils freetype2 libx11 libxext libxi libxtst libxrender
Optional Deps   : alsa-lib: for basic sound support
                  gtk2: for the Gtk+ 2 look and feel - desktop usage
                  gtk3: for the Gtk+ 3 look and feel - desktop usage
Conflicts       : jdk
Required By     : extra/bcprov
                  extra/beanshell
                  extra/cfr
                  extra/dbeaver
                  extra/ditaa
                  extra/eclipse-ecj
                  extra/freecol
                  extra/freeplane
                  extra/geogebra
                  extra/geotag
                  extra/gpsprune
                  extra/jadx
                  extra/java-avalon-framework
                  extra/java-batik
                  extra/java-commons-daemon
                  extra/java-commons-io
                  extra/java-commons-lang
                  extra/java-commons-logging
                  extra/java-hamcrest
                  extra/java-jline
                  extra/java-rhino
                  extra/java-rxtx
                  extra/java-xmlgraphics-commons
                  extra/jlatexmath
                  extra/jmol
                  extra/josm
                  extra/jruby
                  extra/keycloak-hcaptcha
                  extra/keycloak-metrics-spi
                  extra/kotlin
                  extra/ktlint
                  extra/languagetool
                  extra/leiningen
                  extra/libreoffice-extension-writer2latex
                  extra/pdftk
                  extra/perl-inline-java
                  extra/plantuml
                  extra/plantuml
                  extra/plantuml-server
                  extra/plantuml-server
                  extra/procyon-decompiler
                  extra/protege
                  extra/sbt
                  extra/schemacrawler
                  extra/sdedit
                  extra/shattered-pixel-dungeon
                  extra/sweethome3d
                  extra/tomcat10
                  extra/tomcat8
                  extra/tomcat9
                  extra/zaproxy
Optional For    : local/libbluray: BD-J library
                  local/libjpeg-turbo: for TurboJPEG Java wrapper
                  local/libjxl: for JNI bindings
                  local/libreoffice-fresh: adds java support
                  local/opencv: Java interface
                  extra/bettercap-caplets: java caplets
                  extra/brltty: Java support
                  extra/csound: java integration
                  extra/facter: jruby support
                  extra/languagetool: needed for the GUI version
                  extra/libbluray: BD-J library
                  extra/libguestfs: for Java bindings
                  extra/libjpeg-turbo: for TurboJPEG Java wrapper
                  extra/libjxl: for JNI bindings
                  extra/libreoffice-fresh: adds java support
                  extra/libreoffice-still: adds java support
                  extra/libsvm: for java bindings
                  extra/nomad: for java driver
                  extra/nomad: for java driver - headless
                  extra/octave: java support
                  extra/opencv: Java interface
                  extra/opencv-cuda: Java interface
                  extra/polymake: java module
                  extra/ruby-concurrent: jruby support
                  extra/spring: java-based bots
                  extra/swi-prolog: for using Prolog from Java
                  extra/texlive-binextra: for utilities like arara, texplate
                  extra/texlive-latexextra: for pdfannotextractor
MakeDep For     : extra/chromium
                  extra/cvc4
                  extra/electron23
                  extra/electron27
                  extra/electron28
                  extra/electron29
                  extra/electron30
                  extra/mysql-workbench
Package Size    : 41.18 M
Download Size   : 0.00 B
Installed Size  : 187.41 M
Packager        : Tomasz "Ludvick" Niedzielski <ludvick0@gmail.com>
Build Date      : 2024-04-27 18:28:47
SHA-256 Sum     : 0774c9869fea600a38be28641ffaa5fea27befd820801960b5f8f019102f6962

How to modify above awk script, to remove/omit lines that start with local/ and, I suppose, might appear in other section too. I mean in Required By and/or in MakeDep For.
And finally get this:

Name            : jre
Base            : jdk
Repository      : ls-aur
File            : jre-22.0.1-2-x86_64.pkg.tar.zst
Version         : 22.0.1-2
Description     : Oracle Java Runtime Environment
Architecture    : x86_64
URL             : https://www.oracle.com/java/
Licenses        : LicenseRef-custom
Provides        : java-runtime=22 java-runtime-jdk22 jre22-jdk=22.0.1-2 java-runtime-headless=22 java-runtime-headless-jdk=22 jre22-jdk-headless=22.0.1-2
Requires        : java-runtime-common ca-certificates-utils freetype2 libx11 libxext libxi libxtst libxrender
Optional Deps   : alsa-lib: for basic sound support
                  gtk2: for the Gtk+ 2 look and feel - desktop usage
                  gtk3: for the Gtk+ 3 look and feel - desktop usage
Conflicts       : jdk
Required By     : extra/bcprov
                  extra/beanshell
                  extra/cfr
                  extra/dbeaver
                  extra/ditaa
                  extra/eclipse-ecj
                  extra/freecol
                  extra/freeplane
                  extra/geogebra
                  extra/geotag
                  extra/gpsprune
                  extra/jadx
                  extra/java-avalon-framework
                  extra/java-batik
                  extra/java-commons-daemon
                  extra/java-commons-io
                  extra/java-commons-lang
                  extra/java-commons-logging
                  extra/java-hamcrest
                  extra/java-jline
                  extra/java-rhino
                  extra/java-rxtx
                  extra/java-xmlgraphics-commons
                  extra/jlatexmath
                  extra/jmol
                  extra/josm
                  extra/jruby
                  extra/keycloak-hcaptcha
                  extra/keycloak-metrics-spi
                  extra/kotlin
                  extra/ktlint
                  extra/languagetool
                  extra/leiningen
                  extra/libreoffice-extension-writer2latex
                  extra/pdftk
                  extra/perl-inline-java
                  extra/plantuml
                  extra/plantuml
                  extra/plantuml-server
                  extra/plantuml-server
                  extra/procyon-decompiler
                  extra/protege
                  extra/sbt
                  extra/schemacrawler
                  extra/sdedit
                  extra/shattered-pixel-dungeon
                  extra/sweethome3d
                  extra/tomcat10
                  extra/tomcat8
                  extra/tomcat9
                  extra/zaproxy
Optional For    : extra/bettercap-caplets: java caplets
                  extra/brltty: Java support
                  extra/csound: java integration
                  extra/facter: jruby support
                  extra/languagetool: needed for the GUI version
                  extra/libbluray: BD-J library
                  extra/libguestfs: for Java bindings
                  extra/libjpeg-turbo: for TurboJPEG Java wrapper
                  extra/libjxl: for JNI bindings
                  extra/libreoffice-fresh: adds java support
                  extra/libreoffice-still: adds java support
                  extra/libsvm: for java bindings
                  extra/nomad: for java driver
                  extra/nomad: for java driver - headless
                  extra/octave: java support
                  extra/opencv: Java interface
                  extra/opencv-cuda: Java interface
                  extra/polymake: java module
                  extra/ruby-concurrent: jruby support
                  extra/spring: java-based bots
                  extra/swi-prolog: for using Prolog from Java
                  extra/texlive-binextra: for utilities like arara, texplate
                  extra/texlive-latexextra: for pdfannotextractor
MakeDep For     : extra/chromium
                  extra/cvc4
                  extra/electron23
                  extra/electron27
                  extra/electron28
                  extra/electron29
                  extra/electron30
                  extra/mysql-workbench
Package Size    : 41.18 M
Download Size   : 0.00 B
Installed Size  : 187.41 M
Packager        : Tomasz "Ludvick" Niedzielski <ludvick0@gmail.com>
Build Date      : 2024-04-27 18:28:47
SHA-256 Sum     : 0774c9869fea600a38be28641ffaa5fea27befd820801960b5f8f019102f6962

?

Asked By: ludvick

||

Assumptions:

  • remove all values (2nd column) that start with local/

One idea would be to skip adding an entry to the vals[] array if the value starts with local/; modifying OP’s current code:

#### replace this:

vals[++numVals] = substr($0,valInBeg)

#### with this:

val = substr($0,valInBeg)
if (! (val ~ /^local[/]/) ) vals[++numVals] = val

We’re not given a sample set of input so I came up with the following after reviewing OP’s previous question:

$ cat pacinfo.out
Name:           puddletag
Base:           puddletag
Repository:     local
Version:        2.3.0-2
Description:    An audio tag editor for GNU/Linux
Architecture:   any
URL:            https://docs.puddletag.net/
Licenses:       GPL-3.0-or-later
Groups:         modified
Requires:       python-certifi
Requires:       python-charset-normalizer
Requires:       local/first_occurence
Requires:       python-configobj
MakeDep for:    python-certifi
MakeDep for:    python-certifi
MakeDep for:    local/thing: 1 2 3 4 5
MakeDep for:    python-certifi
Optional For:   python-levenshtein: faster duplicate matching
Optional For:   local/something: 1 2 3 4
Optional For:   python-lxml: additional tag sources
Optional For:   python-pyacoustid: AcoustID support
Required By:    extra/bcprov
Required By:    extra/beanshell
Required By:    local/other_thing: a b c
Required By:    extra/cfr
Package Size:   0.00 B
Download Size:  0.00 B
Installed Size: 4.84 M
Packager:       Tomasz "Ludvick" Niedzielski <ludvick0@gmail.com>
Build Date:     2024-05-11 03:22:46
Install Date:   2024-05-11 03:23:57
Install Script: No
Install Reason: Dependency
Validated By:   SHA-256
Validated By:   Signature

NOTE: there are 4 occurences of local/ in the above data set

Running OP’s modified code against this data set generates:

Name            : puddletag
Base            : puddletag
Repository      : local
Version         : 2.3.0-2
Description     : An audio tag editor for GNU/Linux
Architecture    : any
URL             : https://docs.puddletag.net/
Licenses        : GPL-3.0-or-later
Groups          : modified
Requires        : python-certifi python-charset-normalizer python-configobj
MakeDep for     : python-certifi python-certifi python-certifi
Optional For    : python-levenshtein: faster duplicate matching
                  python-lxml: additional tag sources
                  python-pyacoustid: AcoustID support
Required By     : extra/bcprov
                  extra/beanshell
                  extra/cfr
Package Size    : 0.00 B
Download Size   : 0.00 B
Installed Size  : 4.84 M
Packager        : Tomasz "Ludvick" Niedzielski <ludvick0@gmail.com>
Build Date      : 2024-05-11 03:22:46
Install Date    : 2024-05-11 03:23:57
Install Script  : No
Install Reason  : Dependency
Validated By    : SHA-256 Signature
Answered By: markp-fuso
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.