Wrong Ouput when using printf under SFU

I used printf to print the following under SFU,

lrs=`cat lrs`
hrs=`cat hrs`
tp=`cat tp`
printf �\n\n%5sM = $lrs Ohms%5sX = $hrs Ohms%5sT = $tp %%\n\n\n� > file
cat file

With the above script, I used %% after $tp only as a percentage sign and I get only the following output:

% T = value of tp

Any suggestions?

Try reading the man pages for printf. Here's an example...

a=1
b=2
printf '\nValue of a = %s and value of b = %s\n\n' $a $b

Thanks, Ygor! That works.

Ygor,

I tried your suggestion as follows:
a=1
b=2
c=3

Printf � M = %s Ohms X = %s Ohms T = %s %%' $a $b $c

The above format worked fine but when a Command Substitution is used to set the Variables, I noticed that it does not give the right output. I did the following:

#value of lrs = 710
lrs=`cat lrs`
#value of hrs = 910
hrs=`cat hrs`
#value of tp = 3
tp=`cat tp`
printf �\n\nM = %s Ohms X = %s Ohms T = %s %%\n\n\n' $lrs $hrs $tp

The output is:
%hms T = 310

The desired output should be:
M = 710 Ohms X = 910 Ohms T = 3 %

Those quotes in your printf statement look odd. Make sure you are using 'straight quotes', not �directional quotes'.

Or perhaps you have some weird characters in the files? Check by using od -hc lrs etc.
You can remove all non-numeric characters by using lrs=`tr -dc '[0-9]' < lrs`

Hi Ygor,

Sorry, it was just a typographical error from my last message regarding those odd single quotes but in my script they are actually straight quotes. Anyway, I had to do the following long and tedious way just to produce the right output:

Printf '\n\t\t\b\b\bRmin = %s\t\t\t\t\b\b\b\b\b\b\b\bOhms Rmax = %s\t\t\t\t\t\t\b\b\b\b\bOhms Tilt = %s\t\t\t\t\t\t\t\t\b\b\b\b%%' $lrs $hrs $tp

Output:

     Rmin = 710 Ohms       Rmax = 910 Ohms       Tilt = 3 %

From the above printf statement, I noticed that if I use two or more variables, the numeric & non-numeric variables overwrite each other depending on their length. I need the non-numeric characters in my variables so I can't remove those. Thus, I had to utilize series of tab and backspace characters so it would get the desired output. Is there an easier way to do this?