![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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). |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|