Wednesday, December 15, 2010

How to stretch a flat file to a fixed length with awk

I never fail to wonder at the power of unix commands. Today's story is related to the need to manage a supposed-to-be fixed length flat file in which some records end many characters before the desired length is reached.

In such cases awk does a hell of a job with just a one-liner:
awk '{printf "%-116s\n",$0 }' RS="\r\n" input.txt > output.txt
That's it :-)

No comments: