Results 1 to 2 of 2

Thread: awk error

  1. #1
    Join Date
    Apr 2006
    Posts
    16

    Unanswered: awk error

    I have an awk script that I am trying to run from the command prompt and for some reason it errors out at the gsub and sub part.

    Here is what I enter on the command line

    awk - f /usr/appl/riv/home/testriv/awk/riv_feed_import.awk /usr/appl/riv/home/testriv/data/eagle_ac

    and the awk script part where its failing is-

    {
    # remove trailing spaces
    sub(/[ \t]+$/, ""); # set number of placeholders for bcp
    myPlaceHolders=substr(OFS_PLACE_HOLDERS,0,NUM_OUTP UT_COLS-NF-1);
    # change FS to OFS
    reFS = "[\\" FS "]";
    gsub(reFS,OFS);
    # write out the bcp formatted data feed
    print FEED_CD,STAGE_TABLE,$0,myPlaceHolders > FILENAME ".bcp";
    }

  2. #2
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    248
    First of all: awk comes in several versions. The sub and gsub functions tipically belong to the enhanced '85 version. Previously I worked on an old Solaris 2.5 OS where awk invoked the original '77 version. If I had to use extended functionality I had to use nawk instead. There are more systems like that and you should check this out because your sub fubction seems perfectly right to me.

    Second: To my knowledge the sub and gsub functions only operate with literal regexp's, not with parameterized ones. My way of working around this would be creating a shellscript that first writes an awk commandfile to disk (with the rexexp dynamically substituted from a variable) and then executes this file.

    Third: If it's your objective here to change the fieldseparator which is performed on $0 you should do it like 'OFS = fieldseparator'. I believe your gsub tries to substitute every occurance of FS or backslash in $0 with the OFS but (g)sub only operates on strings and fieldseparators are not part of that.

    Regards
    Last edited by Tyveleyn; 08-02-06 at 11:40.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •