Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awk syntax errors #3

Open
pietrushnic opened this issue May 29, 2023 · 3 comments
Open

awk syntax errors #3

pietrushnic opened this issue May 29, 2023 · 3 comments

Comments

@pietrushnic
Copy link
Member

It looks like having the correct version of awk in the system is important:

(venv) [21:55:24] pietrushnic:contribution-stats git:(master) $ ./contribution-stats list -r coreboot -d 01/02/2021 -o coreboot.csv
Listing contributions for only selected repository: coreboot...
Listing contributions for: coreboot, after: 01/02/2021
awk: line 10: syntax error at or near ,
awk: line 15: syntax error at or near next
awk: line 18: syntax error at or near ,
awk: line 19: syntax error at or near ,
(venv) [21:56:15] pietrushnic:contribution-stats git:(master) $ awk
Usage: mawk [Options] [Program] [file ...]

Program:
    The -f option value is the name of a file containing program text.
    If no -f option is given, a "--" ends option processing; the following
    parameters are the program text.

Options:
    -f program-file  Program  text is read from file instead of from the
                     command-line.  Multiple -f options are accepted.
    -F value         sets the field separator, FS, to value.
    -v var=value     assigns value to program variable var.
    --               unambiguous end of options.

    Implementation-specific options are prefixed with "-W".  They can be
    abbreviated:

    -W version       show version information and exit.
    -W dump          show assembler-like listing of program and exit.
    -W help          show this message and exit.
    -W interactive   set unbuffered output, line-buffered input.
    -W exec file     use file as program as well as last option.
    -W random=number set initial random seed.
    -W sprintf=number adjust size of sprintf buffer.
    -W posix_space   do not consider "\n" a space.
    -W usage         show this message and exit.
(venv) [21:56:17] pietrushnic:contribution-stats git:(master) $ sudo apt install awk
[sudo] password for pietrushnic:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package awk is a virtual package provided by:
  original-awk 2018-08-27-1
  mawk 1.3.4.20200120-2
  gawk 1:5.1.0-1
You should explicitly select one to install.

E: Package 'awk' has no installation candidate
(venv) [21:56:29] pietrushnic:contribution-stats git:(master) $ sudo apt install gawk
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  gawk-doc
The following NEW packages will be installed:
  gawk
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 605 kB of archives.
After this operation, 2,515 kB of additional disk space will be used.
Get:1 http://debian-archive.trafficmanager.net/debian bullseye/main amd64 gawk amd64 1:5.1.0-1 [605 kB]
Fetched 605 kB in 6s (93.5 kB/s)
Selecting previously unselected package gawk.
(Reading database ... 89491 files and directories currently installed.)
Preparing to unpack .../gawk_1%3a5.1.0-1_amd64.deb ...
Unpacking gawk (1:5.1.0-1) ...
Setting up gawk (1:5.1.0-1) ...
Processing triggers for man-db (2.9.4-2) ...
(venv) [21:56:51] pietrushnic:contribution-stats git:(master) $ awk --help
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
POSIX options:          GNU long options: (standard)
        -f progfile             --file=progfile
        -F fs                   --field-separator=fs
        -v var=val              --assign=var=val
Short options:          GNU long options: (extensions)
        -b                      --characters-as-bytes
        -c                      --traditional
        -C                      --copyright
        -d[file]                --dump-variables[=file]
        -D[file]                --debug[=file]
        -e 'program-text'       --source='program-text'
        -E file                 --exec=file
        -g                      --gen-pot
        -h                      --help
        -i includefile          --include=includefile
        -l library              --load=library
        -L[fatal|invalid|no-ext]        --lint[=fatal|invalid|no-ext]
        -M                      --bignum
        -N                      --use-lc-numeric
        -n                      --non-decimal-data
        -o[file]                --pretty-print[=file]
        -O                      --optimize
        -p[file]                --profile[=file]
        -P                      --posix
        -r                      --re-interval
        -s                      --no-optimize
        -S                      --sandbox
        -t                      --lint-old
        -V                      --version

To report bugs, see node `Bugs' in `gawk.info'
which is section `Reporting Problems and Bugs' in the
printed version.  This same information may be found at
https://www.gnu.org/software/gawk/manual/html_node/Bugs.html.
PLEASE do NOT try to report bugs by posting in comp.lang.awk,
or by using a web forum such as Stack Overflow.

gawk is a pattern scanning and processing language.
By default it reads standard input and writes standard output.

Examples:
        awk '{ sum += $1 }; END { print sum }' file
        awk -F: '{ print $1 }' /etc/passwd
(venv) [21:56:54] pietrushnic:contribution-stats git:(master) $ ./contribution-stats list -r coreboot -d 01/02/2021 -o coreboot.csv
Listing contributions for only selected repository: coreboot...
Listing contributions for: coreboot, after: 01/02/2021
(venv) [21:56:59] pietrushnic:contribution-stats git:(master) $

If this kind of problem will be repeated by other users we should consider checking for awk version.

@macpijan
Copy link
Member

I think gawk is the most common in distributions. But it may be a valid point.

@pietrushnic
Copy link
Member Author

Debian 11 I was using had mawk as default.

@pietrushnic
Copy link
Member Author

Another issue with syntax under mawk/awk:

+ awk '-F[;]' -v repo=coreboot '
              /__COMMIT_START__/ {
                  getline
                  commit = $1
                  author = $2
                  date = $4
                  subject = $5
                  reviewed_on = ""
                  print "Commit: " commit, "Author: " author, "Date: " date, "Subject: " subject
                  getline
                  while ($0 != "__COMMIT_END__") {
                      if (match($0, /Reviewed-on: (.*)/, m)) {
                          reviewed_on = m[1]
                      }
                      getline
                  }
                  next
              }
              /files? changed/ {
                  if (match($0, /([0-9]+) insertion/, m)) insertions = m[1]
                  if (match($0, /([0-9]+) deletion/, m)) deletions = m[1]
                  printf "%s;%s;%s;%s;%s;%d;%d;%s\n", commit, author, date, repo, reviewed_on, insertions, deletions, subject
                  insertions = deletions = 0
                  reviewed_on = ""
              }
          '
awk: line 12: syntax error at or near ,
awk: line 17: syntax error at or near next
awk: line 20: syntax error at or near ,
awk: line 21: syntax error at or near ,

After installing gawk default awk was replaced, and now the script works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants