How can I fit a 1024 character file in a unix environment?
I have a file that I need to fill each line with spaces up to about 1100 characters from a bash
script. Each line in the file is currently 900 characters long.
The natural way to do this is
awk -F, '{printf("%-1100s\n",$0)}' src.txt > dst.txt
However, I get the error
awk: formatted string too long
record number 1
After some experimentation and searching on the web, I determined that the max formatted string length awk
can handle 1024.
Is there a better way to get around this limitation?
(note: I am running on SunOS 5.10 and I cannot add GNU tools etc. to it)
source to share
If you have installed perl
in the system (probably yes), you can install the script as follows and then run it as pad.pl input.txt 1100 > output.txt
.
#! /usr/bin/perl
open (INPUT, "<$ARGV[0]");
$LENGTH=$ARGV[1];
while (<INPUT>) {
chomp($_);
while (length($_) < $LENGTH ) { $_ = $_." "; }
print $_."\n";
}
close INPUT;
source to share