Format output in columns in ksh

Hi,
I have following output from ksh script (about 60 lines, may be less or more).

1) Word1
2) Word2
3) Word3
..............
59) Word58
60) Word59

I want to format it in 3 columns.

1) Word1            21) Word21             41) Word41
2) Word2            22) Word22             42) Word42
.............              ....................             ................
20) Word20        40) Word40             59) Word59



Thanks
IKeystoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

point_pleasantCommented:
pr -ts" " --columns 3 filename
0
point_pleasantCommented:
oops output is from ksh script so

kshscriptname | pr -ts" " --columns 3
0
IKeystoneAuthor Commented:
Here the part of script that form output. BTW , OS - HP-UX

counter=0
set -A arg_array $WordList

for arg in $WordList
do
      add_counter=`expr $counter + 1`
      printf "%-1s %-20s\n" "$add_counter)" "$arg"
      counter=`expr $counter + 1`
done
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

point_pleasantCommented:
so redirect the output to the shell script to the pr command or do you need the ksh out put to be in columns?

if so try something like


counter=0
rm /path/to/tmpfile

set -A arg_array $WordList

for arg in $WordList
do
      add_counter=`expr $counter + 1`
      printf "%-1s %-20s\n" "$add_counter)" "$arg"  >> /path/to/tmpfile
      counter=`expr $counter + 1`
done
cat /path/to/tmpfile |pr -ts" " --columns 3

#continue with script
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
point_pleasantCommented:
if you want to be good scripter check t see if tmp file exists first  otherwise might get an error

TEMPFILE="/tmp/tmpfile"

if [[ -e TEMPFILE ]]
  then
        rm $TEMFILE
  fi
0
Gerwin Jansen, EE MVETopic Advisor Commented:
>> about 60 lines, may be less or more
so if you get 80 lines, you want 4 columns and if you get 101 lines, you want 6 columns?
0
point_pleasantCommented:
re expert comment:

if num cols variable then let me know can always do a line count and if stmt to vary the num of cols requested from the pr command
0
point_pleasantCommented:
thanks Ikeystone glad to help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.