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 > 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
Shell script to format a .CSV data Uday1982 Shell Programming and Scripting 8 02-04-2008 05:28 AM
how to number format a data file without using SED? Cactus Jack UNIX for Dummies Questions & Answers 3 01-12-2008 07:47 PM
Add data in days:hours:min:sec format krishna_sicsr Shell Programming and Scripting 1 03-17-2007 11:39 AM
kstat - format of output data? ozvena UNIX for Dummies Questions & Answers 4 06-16-2005 04:35 PM
format data inquirer Shell Programming and Scripting 2 09-24-2003 06:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-29-2006
ahan ahan is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 5
data format from (4.56 0.7) -> 4.6(7) awk?!

Hi,
I have to manipulate a data file which say reads like this
{$index $value $error_on_value}

aa 4.56 0.7
bb 123.456 0.00987
cc 987654 321
.
.
in easily human readable format of type

aa 4.6(7)
bb 123.456(1)
cc 9.877(3)e+05

value rounded to 4.6 with error of 0.7 on the last significant digit.
In 2nd row, error is rounded off
in 3rd, exponential form suits better for this. but this is optional. (In awk, its printf with "%g" option )


I tried to play with awk, where I formatted first with say
'{printf "%d\t1.3e\t%1.0e\n",$1,$2,$3}'
then can manipulate to get it dirty way to the type mentioned in row 3.

I am sure there is smart way to do this. If I get any suggestion, it would greatly improve my experience, so thanks in advance.

ps: My actual data file has (2n+1) number of columns. 1st being index, then even ones are value and odd ones are error on that. Should there be smart way to ask script to sense "n" (say using awk NF), and automate that, that would be cool.
  #2 (permalink)  
Old 05-03-2006
ahan ahan is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 5
bumping up

Please look at this problem, and let me know if something can be done or not clear. I am shamelessly bumping it up, for I need help.

thanks.
  #3 (permalink)  
Old 05-03-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
I don't understand your 'rounding' logic.
Could you elaborate abit more, pls
  #4 (permalink)  
Old 05-07-2006
ahan ahan is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 5
Thumbs down

Thanks for asking...
Suppose your a output file that contains value of some observable and error-bar on that. look like this:
$cat datafile.txt
123.4567 0.0098
.
.

re-writing the first row (exp. format. %1.5e)
123.4567 1.234567 e+02
000.0098 9.80000 e-03
-----------------
If you ask me to read it, for better human comprehension, I would perhaps round off the values appropriately and say the value is 123.457 with error of +-1 on the last digit. that I write as 123.457(1).
  #5 (permalink)  
Old 05-07-2006
ahan ahan is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 5
I am a new user here.. do not know how that thumbs down symbol got attached in the prev. reply. dont mean disrespect none to nobody
also I noticed that i did not give right example.

123.4567
000.0098

should be 123.46(1).

error determine at which place the rounding should occur in the mean/main value(1st col). this case is little non-trivial as error itself is rounded off to nearer value. We look for only one (significant) digit from error, that rounds 0.0098 as 0.01. Now in the mean value (123.4567) its useless to go with precision better than 0.01. so we would round off the value upto two digits after decimal. that makes it 123.46.

Last edited by ahan; 05-07-2006 at 09:04 PM.. Reason: incomplete.
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