[Solved] Removing Leading Zeros within awk file [duplicate]
Try this: sub(/^0+/, “”, $2)? $ awk ‘BEGIN{b=”000000000000787301″; sub(/^0+/, “”, b); print b;}’ 787301 or typecast it by adding zero: $ awk ‘BEGIN{b=”000000000000787301″; print b+0;}’ 787301 update A working example based on comments: $ echo ‘E2EDP19001 02002000000000000797578’ | awk ‘{$2 = substr($2,6); sub(/^0+/, “”, $2); print $2;}’ 797578 or, preserve $2: $ echo ‘E2EDP19001 02002000000000000797578’ … Read more