Hello,
When I use AWK I seem to have a problem with the newline character attaching itself to the last field I request. I use AWK to gather fields from a line in a log file. When I ask AWK to grab the last field, it takes the number plus the newline character at the end of the line. I would like to know of anyway of making AWK ignore the newline character when gathering field values. The reason I want to drop the newline character is that I want to add the string $MSU (passed by shell script) to the end of the line without this error occuring.
------------------------------------------------------------
#!/bin/sh
fieldNum=$1
/usr/bin/awk -v field=$fieldNum 'BEGIN{numOfFields=split(field,fieldList,",")} {
for ( x = 2 ; x < NF ; x += 2 )
fields[$x] = sprintf("%s",$(x+1));
for ( i=1;i<=numOfFields;i++ ) {
if ( fields[fieldList[i]] != "" )
printf fields[fieldList[i]] " " ;
}
print "'"$MSU"'";
}
'
---------------------------------------------------------
Any help on the matter would be greatly appreciated.
_David