The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
append zero's in the begining ganapati UNIX for Dummies Questions & Answers 3 01-17-2008 09:41 AM
Adding a new HDD jeffreydavisjr UNIX for Dummies Questions & Answers 5 10-16-2006 12:13 PM
adding licenses andryk SUN Solaris 0 05-19-2004 07:26 AM
Adding 2 numbers Viper01 Shell Programming and Scripting 7 04-17-2004 09:59 AM
Leading Zero's dbrundrett Shell Programming and Scripting 5 12-19-2003 06:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-21-2008
Registered User
 

Join Date: Feb 2007
Posts: 110
adding zero's

Hi
I am comparing two files, 100th column have formatting issue
i mean 1 file have scale 4 and anothe file scale 2 ,if scale 2 need to add two zeros.Please any idea how to add two zers to 100th coulmn if scale is 2

file 1
.................1234.2000

file2

................1234.20

Thanks,
MR
Reply With Quote
Forum Sponsor
  #2  
Old 07-21-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Wink printf reformats output, or can do a bc function

Code:
> x1=1234.20
> echo $x1
1234.20
> echo $(printf "%.4f" "$x1")
1234.2000
something else to think about

Code:
> x2=1234.2000
> x3=$(echo "$x1"-"$x2" | bc)
> echo $x3
0
Perhaps one of these approaches will help you.
Reply With Quote
  #3  
Old 07-21-2008
Registered User
 

Join Date: Feb 2007
Posts: 110
Hi
Thanks for your reply .when comparing two files this 100th filed giving differences due to formatting issue .Is there any way to achive using sed or awk

Thanks in advance
MR
Reply With Quote
  #4  
Old 07-21-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 568
Force awk to compare the string numerically...

Code:
echo 1234.2000 | awk '{print $0+0}'
1234.2
echo 1234.20 | awk '{print $0+0}'
1234.2
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 01:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0