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`
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:
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?