If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-13-06, 16:25
memonks memonks is offline
Registered User
 
Join Date: Apr 2006
Posts: 16
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";
}
Reply With Quote
  #2 (permalink)  
Old 08-02-06, 08:41
Tyveleyn Tyveleyn is offline
Registered User
 
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 10:40.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On