Decrease Decimals in Fourth Column In a Text File

Aaron Perry

I have a text file where the fourth column contains numbers with many decimal places. I need to reduce the places to 0.1 decimal place.

Data:

2015041416 KBOS TMP2M 62.034
2015041417 KBOS TMP2M 65.0826
2015041418 KBOS TMP2M 66.7278
2015041419 KBOS TMP2M 67.5033
2015041420 KBOS TMP2M 67.1731
2015041421 KBOS TMP2M 65.9252
2015041422 KBOS TMP2M 62.7644
2015041423 KBOS TMP2M 60.8136
2015041500 KBOS TMP2M 56.167
2015041501 KBOS TMP2M 55.7116
2015041502 KBOS TMP2M 51.8512
2015041503 KBOS TMP2M 51.6005
2015041504 KBOS TMP2M 50.1643
2015041505 KBOS TMP2M 49.2167
2015041506 KBOS TMP2M 48.273
2015041507 KBOS TMP2M 46.6407
Cyrus
awk '{printf "%s %s %s %.1f\n",$1, $2, $3, $4}' file > file2

Output to file2:

2015041416 KBOS TMP2M 62.0
2015041417 KBOS TMP2M 65.1
2015041418 KBOS TMP2M 66.7
2015041419 KBOS TMP2M 67.5
2015041420 KBOS TMP2M 67.2
2015041421 KBOS TMP2M 65.9
2015041422 KBOS TMP2M 62.8
2015041423 KBOS TMP2M 60.8
2015041500 KBOS TMP2M 56.2
2015041501 KBOS TMP2M 55.7
2015041502 KBOS TMP2M 51.9
2015041503 KBOS TMP2M 51.6
2015041504 KBOS TMP2M 50.2
2015041505 KBOS TMP2M 49.2
2015041506 KBOS TMP2M 48.3
2015041507 KBOS TMP2M 46.6

Same output with bash and without awk:

printf "%s %s %s %.1f\n" $(< file) > file2

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Convert Number of Decimals Through a Text File

From Dev

C# Round decimals from text file

From Dev

Is it possible with Gedit or the command line to modify every fourth line of a text file?

From Dev

Is it possible with Gedit or the command line to modify every fourth line of a text file?

From Dev

Rounding a float number to 2 decimals to write it to a text file

From Java

Decrease the width of column in a GridLayout

From Dev

How to decrease the boldness of a text?

From Dev

Split a column in a text file

From Dev

column with mixed decimals

From Dev

Resizing of text ignores decimals

From Dev

Decrease and increase a column in EF Core

From Dev

3-Dimensional Plot in GnuPlot where color is a fourth column in my data file?

From Java

Take nth column in a text file

From Dev

Text file to the specified datatable column

From Dev

How to sum column text file

From Dev

Parsing Text File By Column Pattern

From Dev

extract a column from a text file

From Dev

extract a column from text file

From Dev

Javascript - Sum table column with decimals

From Dev

Count every fourth word in a file

From Dev

Java text file remove doubles from four column text file

From Dev

R: check if column values decrease / increase

From Dev

R: check if column values decrease / increase

From Dev

How to decrease the height of the input text field in bootstrap?

From Dev

edit text height getting decrease on click

From Dev

jQuery - Increase textarea on click; Decrease after if not text;

From Dev

How to decrease body text size only in word?

From Dev

Regular expression to search column in text file

From Dev

How to add the fetched file time to the text column?

Related Related

HotTag

Archive