Language feature idea ...

  • Oliver Fromme

    Oliver Fromme - 2002-11-22


    This might not be the right place to suggest an

    extension to the awk language, but I'd like to

    mention it here anyway.  :-)

    There's one thing that always bothered me since
    I started using awk many years ago:  You cannot
    easily get a string of multiple fields.  It's easy to
    get single fields ($1, $2, ..., $NF) and all fields at
    once ($0), but often I find myself in the need to
    get a string of several consecutive fields.  A syntax
    like $[3,5] would be nice to get a string consisting
    of fields 3 through 5.

    On a related note, sometimes it would be really
    useful to have a "shift" command like the bourne
    shell.  I.e. when you write "shift 3", then the contents
    of $4 will be moved to $1, and $5 moved to $2 etc..,
    and the contents of $0 are updated appropriately.

    Well, those are my Christmas wishes for this year.

    Best regards

    • Neil Parks

      Neil Parks - 2003-10-22

      Sounds like some good ideas.  You might want to write to Arnold Robbins, maintainer of Gawk.

    • Neil Parks

      Neil Parks - 2003-10-23

      function consecfields(first, last,   string_holder, i) \   {
        for (i = first; i <= last; i++)
          string_holder = string_holder $i
        return string_holder

      some_variable = consecfields(3, 5)

    • Andrew

      Andrew - 2003-10-29

      I'd agree with Neil - something that did these _could_ be introduced in Awka, but it'd be much better if Gawk had the new feature as well so it could be implemented in a consistent manner in both products.

      Yes, there's the workaround of making these AWK functions in your script, however these will always be slower than having it a builtin function where the processing is done in C.  Perhaps I'm just a speed freak ;)


Log in to post a comment.