data format from (4.56 0.7) -> 4.6(7) awk?!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting data format from (4.56 0.7) -> 4.6(7) awk?!
# 1  
Old 04-29-2006
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  
Old 05-03-2006
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  
Old 05-03-2006
I don't understand your 'rounding' logic.
Could you elaborate abit more, pls
# 4  
Old 05-07-2006
PHP

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  
Old 05-07-2006
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 Smilie
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 10:04 PM.. Reason: incomplete.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format Data - awk ..

/clusters/cluster-1/exports/storage-views/M1_CRE03_SV: Name Value ------------------------ --------------------------------------------------------------------------------------------------- caw-enabled true controller-tag - initiators ... (7 Replies)
Discussion started by: greycells
7 Replies

2. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

3. Shell Programming and Scripting

Converting text files to xls through awk script for specific data format

Dear Friends, I am in urgent need for awk/sed/sh script for converting a specific data format (.txt) to .xls. The input is as follows: >gi|1234|ref| Query = 1 - 65, Target = 1677 - 1733 Score = 8.38, E = 0.6529, P = 0.0001513, GC = 46 fd sdfsdfsdfsdf fsdfdsfdfdfdfdfdf... (6 Replies)
Discussion started by: Amit1
6 Replies

4. UNIX for Dummies Questions & Answers

Des/awk for change format and adding integers in a column of data?

Greetings! I need a quick way to change the format in a table of data Here is an example of the input: 10 72 Value=177 VDB=0.0245 Value4=0,0,171,0 10 274 Value=238 VDB=0.0433 Value4=29,0,205,0 10 312 Value=222 VDB=0.0384 Value4=8,0,190,19 10 540 Value=405 VDB=0.0391 Value4=13,30,153,195... (3 Replies)
Discussion started by: Twinklefingers
3 Replies

5. Shell Programming and Scripting

awk - script help: column to row format of data allignment?

Experts Good day, I have the following data, file1 BRAAGRP1 A2X B2X C2X D2X BRBGRP12 A3X B3X Z10 D09 BRC1GRP2 LO01 (4 Replies)
Discussion started by: rveri
4 Replies

6. Shell Programming and Scripting

Need help getting data into legible format...maybe awk?

Good morning, I am still learning the powers of awk and perl. I am in need of a bit of help. I have a script on one of my launch systems...if that is even the word for it. Basically you can only ssh to a system if you are connected to this system due to firewalls. So from that system, I... (2 Replies)
Discussion started by: brianjb
2 Replies

7. Shell Programming and Scripting

Arrange / format data using awk

Input 217:fngadi4osa:fngadi4osa:M 217:415744:N/A 227:fngadi4osa:fngadi4osa: M 227:51200:N/A 228:fngadi4osa:fngadi4osa: M 228:102400:N/A 65:sapgt04:sapgt04: M 65:104448:N/A 228:fngadi4osa:fngadi4oma: M 228:102400:N/A Output 217:fngadi4osa:fngadi4osa:M 217:415744:N/A... (3 Replies)
Discussion started by: greycells
3 Replies

8. Shell Programming and Scripting

Using Awk for extracting data in specific format

please help me writing a awk script 001_r.pdb 0.0265185 001_r.pdb 0.0437049 001_r.pdb 0.0240642 001_r.pdb 0.0310264 001_r.pdb 0.0200482 001_r.pdb 0.0146746 001_r.pdb 0.0351344 001_r.pdb 0.0347856 001_r.pdb 0.036119 001_r.pdb 1.49 002_r.pdb 0.0281011 002_r.pdb 0.0319908 002_r.pdb... (5 Replies)
Discussion started by: phoenix_nebula
5 Replies

9. Shell Programming and Scripting

Format - Inventory Row data into Column - Awk - Nawk

Hi All, I have the following file that has computer data for various pcs in my network... Snap of the file is as follows ******************************************************************************* Serial 123456 Computer IP Address lo0:... (1 Reply)
Discussion started by: aavam
1 Replies

10. UNIX for Dummies Questions & Answers

converting a tabular format data to comma seperated data in KSH

Hi, Could anyone help me in changing a tabular format output to comma seperated file pls in K-sh. Its very urgent. E.g : username empid ------------------------ sri 123 to username,empid sri,123 Thanks, Hema:confused: (2 Replies)
Discussion started by: Hemamalini
2 Replies
Login or Register to Ask a Question