The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > Windows & DOS: Issues & Discussions
.
google unix.com



Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Cannot redirect ouput????? minifish Shell Programming and Scripting 3 02-20-2008 12:15 PM
Identifying same character and ouput the sum Raynon Shell Programming and Scripting 12 03-21-2007 11:59 PM
capture the ouput! azmathshaikh Shell Programming and Scripting 0 12-20-2005 07:23 AM
Red Hat - ouput capture juxtaman UNIX for Dummies Questions & Answers 3 04-10-2003 11:31 AM
Locating files and directing ouput klannon Filesystems, Disks and Memory 2 03-11-2002 12:57 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-28-2007
ilak1008 ilak1008 is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
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?
  #2 (permalink)  
Old 05-29-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try reading the man pages for printf. Here's an example...
Code:
a=1
b=2
printf '\nValue of a = %s and value of b = %s\n\n' $a $b
  #3 (permalink)  
Old 05-30-2007
ilak1008 ilak1008 is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
Quote:
Originally Posted by Ygor
Try reading the man pages for printf. Here's an example...
Code:
a=1
b=2
printf '\nValue of a = %s and value of b = %s\n\n' $a $b
Thanks, Ygor! That works.
  #4 (permalink)  
Old 05-31-2007
ilak1008 ilak1008 is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
Quote:
Originally Posted by Ygor
Try reading the man pages for printf. Here's an example...
Code:
a=1
b=2
printf '\nValue of a = %s and value of b = %s\n\n' $a $b
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 %
  #5 (permalink)  
Old 05-31-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
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`
  #6 (permalink)  
Old 06-02-2007
ilak1008 ilak1008 is offline
Registered User
  
 

Join Date: May 2005
Posts: 64
Quote:
Originally Posted by Ygor
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?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0