How to preserve the original whitespace between fields in awk?

If you want to preserve the whitespace you could also try the split function.
In Gnu Awk version 4 the split function accepts 4 arguments, where the latter is the separators between the fields. For instance,

echo "a  2   4  6" | gawk ' {
 n=split($0,a," ",b)
 for (i=1;i<=n; i++)
     line=(line a[i] b[i])
 print line

gives output

a  2   7  6

Leave a Comment