Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am trying to output the results of my shell script using printf. To keep the results aligned in column, I am using tab as:

printf "%s\t %s\t %s\t %s\t %s\t %s\t %s\n" $i $est $var_m $jk $mst $var_M  $Tes >>tmp

But the problem is, for some cases, the results are bit long, as a output of say,

var_M=`echo "scale=8;(-1/$jk + (e(2*$jk)+1)/(e(2*$jk)-1))"|bc -l `

So, it will be better for me, if I can format print to the column, something like:

printf "%s *goto column 20* %s *go to column 30* " $i $est >>tmp

is this possible?

I have checked this thread and also the man pages, but failed to find it. Is this possible?

NB: I do not have any special reason to stick to printf. so any other suitable command that can do the thing (easily) is also welcome.

EDIT: tried: printf "%-2s %-8s\n" $i $est >>tmp which is not clearly working:

4.0 0.17169E-02
5. 0.17156E-02
10. 0.17129E-02

(The 2nd row/2nd column is not aligned, just like the case of list-formatted output)

share|improve this question
    
2 is not enough for "4.0", try with printf "%-20s %-20s\n" $i $est >>tmp –  damphat Aug 13 '13 at 9:17
    
Ah...thanks! Working perfectly. –  BaRud Aug 13 '13 at 9:22
add comment

1 Answer

up vote 5 down vote accepted

Try this:

printf "%-20s %-30s" $i $est >>tmp
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.