The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 09:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 10:19 AM
Number count per number ranges shirleyeow Shell Programming and Scripting 5 12-19-2007 04:06 AM
to print number one less than actual number cdfd123 Shell Programming and Scripting 4 09-06-2007 07:56 AM
number pad in vi c19h28O2 SUN Solaris 5 09-21-2006 03:41 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 08-20-2006
nortypig nortypig is offline
Registered User
  
 

Join Date: Aug 2006
Location: Hobart Tasmania
Posts: 58
Cool why does this number become 0.0 on fprint?

basically helpme.txt has three columns - the first two are decimals and the third is something like 45.5%...

sed is used to discard the % sign as was suggested here earlier...

here is the line of code I'm interested in...

cat helpme.txt | awk '{$1 $2 $3}NR<5{printf("%-20d %-20d %-20.1f\n",$1,$2,$3)}' | sed 's/%//' | sort $3

the output is correct except for the third column - it disappears to 0 values, or rather 0.0

so i am confused. Are there other options I have which don't lose this value? I expected to see 45.5 in the third column of the output. If anyone can give me another hint I would greatly appreciate it as I can't find other alternatives at this point.

-- or is there a way of formatting this output into fixed width columns without it all being the same, ie some fields text and others decimal in the same column?
  #2 (permalink)  
Old 08-20-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
a sample input and the required output .. would be very useful !!!
  #3 (permalink)  
Old 08-20-2006
nortypig nortypig is offline
Registered User
  
 

Join Date: Aug 2006
Location: Hobart Tasmania
Posts: 58
The input would be something like


Code:
435 1345 45.5%
12345 345676 29%

The output is now


Code:
435            1345            0.0
12345         345675         0.0


The third column somehow loses its value when I use the printf formatting to widen the columns... declaring the third column floating point.

thanks
  #4 (permalink)  
Old 08-20-2006
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

Join Date: Oct 2005
Location: Chennai
Posts: 365
it works

Your command works fine for me. I feel the sed isn't necessary and the sort should be based on key - syntax is

Code:
sort -k3


Code:
$>echo "12 13 45.5%" |awk 'NR<5{printf("%-20d %-20d %-20.1f \n " ,$1,$2,$3)}'|sed 's/%//'
12                   13                   45.5


Code:
$>echo "12 13 45.5%" |awk 'NR<5{printf("%-20d %-20d %-20.1f\n",$1,$2,$3)}'
12                   13                   45.5

  #5 (permalink)  
Old 08-20-2006
nortypig nortypig is offline
Registered User
  
 

Join Date: Aug 2006
Location: Hobart Tasmania
Posts: 58
i cut and pasted your code onto my command line and got the same answer as before...

third column is 0.0

what could be causing this then I'm confused.
  #6 (permalink)  
Old 08-20-2006
nortypig nortypig is offline
Registered User
  
 

Join Date: Aug 2006
Location: Hobart Tasmania
Posts: 58
Also, when I add a fourth field why does the output double space the lines?


Code:
echo "12 13 45.5%" |awk 'NR<5{printf("%-20d %-20d %-20d %-20.1f\n",$1,$1,$2,$3)}'

i'm only new at UNIX and it seems there are no end of little traps and caveats which i don't understand
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:53 AM.


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