tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: help with awk



Anything not in a BEGIN{} or END{} block will be applied to each line of the input.

It also seems like you're getting a bit mixed up with shell vs awk variables. With awk, $i is field i of the input. If you want to use the value of a variable named i, like in your loop, then just write i without a dollar sign.

Also, in your for loop you're already grabbing individual fields, so there's no need to split the line: $i will be the ith field of the input line.

Does

    BEGIN { print "# $NetBSD$"; }
    /(^|\n)source =/ {
        for (i = 1; i <= NF; i++) {
           sub("\"","")
           sub(",","")
           if ($i ~ /^https/)
              name=$i
           if ($i ~ /[a-f0-9]{40}/)
              vers=$i
        }
    }
    END { print "DISTFILES+=\t" name "-" vers ".tar.gz" }

do what you want for DISTFILES and give you enough to go on for SITES.?

Given the following line(s) of a file as an example:

source = { git = "https://github.com/Beaglefoot/tree-sitter-awk";, rev = "a799bc5da7c2a84bc9a06ba5f3540cf1191e4ee3" }

and this awk script:

BEGIN { print "# $Net" "BSD$"; }
/(^|\n)source =/ {
         for (i = 1; i <= NF; i++) {
                 sub("\"","")
                 sub(",","")
                 split($i, f, " ")
                 print "field f["$i"]"
                 if (f[$i] ~ /^https/)
                         name=f[6]
                 if (f[$i] ~ /[a-f0-9]{40}/)
                         vers=f[9]
                 print name
                 print vers
         }
         print "DISTFILES+=\t" name "-" vers ".tar.gz"
}
# SITES.name-vers.tar.gz= -url/archive/vers.tar.gz
#/^source = {/ { print "DISTFILES+=\t" name "-" vers ".tar.gz"; }


what do I fix to correctly output
DISTFILES+=	name-vers.tar.gz
SITES.name-vers.tar.gz= -url/archive/vers.tar.gz

where name is the last path part of url?
I know I'm still missing filtering the name from the url, and basically
everything else, as it's been too long since I had to work in awk.


This is to spare myself or whoever updates editor/helix to do the same
copy-pasting 30+ minutes process again and again with every new release.

--
jbowen



Home | Main Index | Thread Index | Old Index