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.


    BEGIN { print "# $NetBSD$"; }
    /(^|\n)source =/ {
        for (i = 1; i <= NF; i++) {
           if ($i ~ /^https/)
           if ($i ~ /[a-f0-9]{40}/)
    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 = "";, rev = "a799bc5da7c2a84bc9a06ba5f3540cf1191e4ee3" }

and this awk script:

BEGIN { print "# $Net" "BSD$"; }
/(^|\n)source =/ {
         for (i = 1; i <= NF; i++) {
                 split($i, f, " ")
                 print "field f["$i"]"
                 if (f[$i] ~ /^https/)
                 if (f[$i] ~ /[a-f0-9]{40}/)
                 print name
                 print vers
         print "DISTFILES+=\t" 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 -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.


Home | Main Index | Thread Index | Old Index