Search code examples
bashunixawkshsunos

How can I pad a file beyond 1024 characters in a unix environment?


I have a file that I need to pad each line with spaces to around 1100 characters from a bash script. Each line in the file currently has 900 characters.

The natural way to to this is

awk -F, '{printf("%-1100s\n",$0)}'  src.txt > dst.txt

However, I get an error telling me

awk: formatted string too long
 record number 1

After some experimentation and searching on the internet, I've determined that the maximum line length of formatted string awk can handle is 1024.

Is there a better way to get around this limitation?

(note: I'm runnin on SunOS 5.10, and I can't add GNU tools to it, etc.)


Solution

  • Get GNU awk.

    $ awk 'BEGIN{printf "%-1100s\n", "foo"}'
         foo
    

    You're probably using old, broken awk - use nawk or /usr/xpg4/bin/awk on Solaris. If you're having this problem with one of them, then use the other one.