Trouble converting columns of integers to floating decimals


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trouble converting columns of integers to floating decimals
# 1  
Old 01-29-2014
Trouble converting columns of integers to floating decimals

I have a document that has 7 columns.

eg.

Code:
$1 $2 $3 $4 $5 $6 $7
string string string string integer integer integer

The 6th and 7th columns are a mix of integers and floating decimals (with 4 decimal places). I need to convert the last 2 columns so that all values are floating decimals w/4 decimal places, while leaving the rest of the worksheet in tact. In all I have 96 documents that need this conversion.

I have been able to output an individual column to a new worksheet in the right format with:

Code:
awk <input_filename ' { printf ("%.4f\n",$7) }' > output filename

However, I don't want to make 2 separate files and concatenate the original, plus the 2 new files and then awk out the columns I need on 96 files.

Thanks

Last edited by Scrutinizer; 01-29-2014 at 03:46 PM.. Reason: code tags
# 2  
Old 01-29-2014
Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.

(Original thread here)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting rows into columns

hi all I need a help ..I have a script that takes has command and its output is like below.. a b a v v a c I am assigning the above outputs to a variable .. <variable name> = <command output> problem here is when I echo the variable ..it gives me output like " a b... (3 Replies)
Discussion started by: shankarb
3 Replies

2. Shell Programming and Scripting

Changing integer columns to floating decimal columns

I have a document that has 7 columns. eg. $1 $2 $3 $4 $5 $6 $7 string string string string integer integer integer The 6th and 7th columns are a mix of integers and floating decimals (with 4 decimal places). I need to convert the last 2 columns so that all... (3 Replies)
Discussion started by: kadm
3 Replies

3. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

4. Programming

Converting columns to matrix

Dear All I would like to convert columns to matrix For example my data looks like this D2 0 D2 0 1.0 D2 0 D2 1 0.308 D2 0 D2 2 0.554 D2 0 D2 3 0.287 D2 0 D2 4 0.633 D2 0 D2 5 0.341 D2 0 D2 6 0.665 D2 0 D2 7 0.698 D2 0 D2 8 0.625 D2 0 D2 9 0.429 D2 0 D2 10 0.698 D2 0 D2 11... (7 Replies)
Discussion started by: bala06
7 Replies

5. Shell Programming and Scripting

converting rows into columns

Hi, I am trying to fetch some values from db and spooling the output to a file. when i query the db for the values, i get the values in following format. PC_1 wf_test1 Test PC_2 wf_test2 Test PC_3 wf_test3 Test But my spool file was created in following format. PC_1 wf_test1 Test... (20 Replies)
Discussion started by: svajhala
20 Replies

6. Shell Programming and Scripting

trouble with gawk and columns

I am trying to make a script that would take the highest value of each columns for example cat file 0 0 0 0 0 8 9 1 3 8 3 9 7 7 7 7 the results would be 7 8 9 9 I found this code, and it takes the highest value with a... (2 Replies)
Discussion started by: gengar
2 Replies

7. Shell Programming and Scripting

PERL- converting exponent value to floating point

Hi Friends, I've an exponent value like, $val="9.57669e-05"; I want to convert this value to floating point value in PERL scripting. I tried googling for the solution, and also asked many perl friends. Unfortunately, I didn't get answer. Could you please help me? Thanks in advance... (4 Replies)
Discussion started by: ganapati
4 Replies

8. UNIX for Dummies Questions & Answers

Integers/floating points in Perl

Hi all I am trying to figure out how to specify integers and floating points specifically in a Perl program. Basically the idea is that I want the user to input an integer and then dependent on that value they get a specific output. Now my problem is that I don't know how to write the... (7 Replies)
Discussion started by: Banni
7 Replies

9. Shell Programming and Scripting

Converting Exponential values to decimals

Hi, I have a number of large (500Mb) txt files in the following format: 8.05475136E+05 9.69428147E+05 1 14 2968.00 3419.00 59.00 59 3.4028235E+38 2 w99-100 8.05464719E+05 9.69435064E+05 1 14 2968.03 3418.50 60.00 60 3.4028235E+38 2 w99-100 8.05454301E+05 ... (4 Replies)
Discussion started by: barrypitts
4 Replies

10. Shell Programming and Scripting

convert Regular decimals to Packed decimals

Hi, I am trying to find if there is a way to convert regular decimal values to Paced decimal values. I tried to find a c program but I could get a Packed converted to regular decimal not the other way round. If not unix please let me know if any other progrimming language I can use to do... (2 Replies)
Discussion started by: mgirinath
2 Replies
Login or Register to Ask a Question