formatting output

Sorry for being a n00b, but I'm having a lot more trouble than I should with formatting the output to the program I finally completed. I'm basically looking for the linux equivalent to setw( ) from c++ so that I can print things in columns like this (but without the underlines lol):

MISSPELLED:      CORRECTED:
whoi              who
holee             hole
ys                yes

I kept trying to get it to work with printf and %15s but it doesn't work when the words are different lengths. Does anyone know how I can properly format this?

Thank you very much!!!

Hi.

printf would seem to do what you want:

$ cat PrintTest
while read BAD GOOD; do
  printf "%-15s %s\n" $BAD $GOOD
done < file1
 
$ cat file1
MISSPELLED: CORRECTED:
whoi who
holee hole
ys yes
 
$ ./PrintTest
MISSPELLED:     CORRECTED:
whoi            who
holee           hole
ys              yes
 
1 Like

Thanks so much!!!! =]

Hi.

For a link and an example of a code that does automatic alignment of data in column fields, see post #5 at Output alignment problem

Best wishes ... cheers, drl

awk '{printf "%-15s %s\n",$1,$2}' file1