# Convert fixed width format to R/S "table" # By KH , based on a script by Doug Bates # Modified for Windows by BDR # Usage: fwf2table -f FORMAT [-s SEP] -o outfile FILE, # where FORMAT is the format string, typically "Ax Ay Az ..." with x, y, # z etc being the widths of the columns and `A' means that the field is # to be interpreted as an ASCII character string with trailing white # space suppressed, and SEP is the record separator to be inserted in # the output (default is a space). require "getopts.pl"; &Getopts("f:s:o:"); die "A format string must be specified.\n" unless $opt_f; $sep = $opt_s ? $opt_s : " "; open outfile, ">$opt_o" || die "no output file"; while (<>) { undef @rec; foreach (unpack($opt_f, $_)) { s/^\s+//; if (/\s/) { $_ = "\"" . $_ . "\""; } elsif (/^$/) { $_ = "NA"; } push(@rec, $_); } print outfile join($sep, @rec), "\n"; }