String indexes are inconsistent with other awks
Bug #26603 reported by
Andrew Snare
This bug affects 3 people
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
mawk (Ubuntu) |
Confirmed
|
Low
|
Unassigned |
Bug Description
The substr() function from within mawk does not function correctly. In particular, the
substr(s,i,n) form returns n-1 characters, instead of n as required. To demonstrate:
% echo "1234" | mawk '{print substr($0,0,3)}'
12
It should display "123"; this can be confirmed by using gawk instead, or trying awk on
the *BSD platforms.
To post a comment you must log in.
It appears the situation is more complex than I thought; string indexing is apparently 1-based,
not 0-based as I previously thought.
The matter is summarised at: <http:// lists.gnu. org/archive/ html/bug- gnu-utils/ 2004-09/
msg00083.html>
Indeed the following works as expected:
% echo 1234 | mawk '{print substr($0,1,3)}'
It may be undesirable behaviour, but it's not a bug per se.
- Andrew