LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-10-2014, 08:24 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 248

Rep: Reputation: 1
shell scrpting - decreasing the decimals of numbers


Hi,

I have columns like this:

Code:
   
        -1.67700444	-0.93558089	-0.03968523
	-1.67191856	0.95738334	2.48905615
	0.02711232	1.89308707	-0.04336284
	1.67950619	0.93385064	2.49129742
I want to reduce the decimals to 6 to have a result like this:

Code:
	-1.677004	-0.935580	-0.039685
	-1.671918	0.957383	2.489056
	0.027112	1.893087	-0.043362
	1.679506	0.933850	2.491297
Any ideas about how I can do this. Thaks for your guide...
 
Old 06-10-2014, 08:43 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,122

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
probably with awk, using printf?
 
Old 06-10-2014, 09:17 AM   #3
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
I hope there are three columns only.
Code:
cat /path/of/file | awk '{printf "%.6f %.6f %.6f\n", $1, $2, $3}'
 
2 members found this post helpful.
Old 06-11-2014, 01:12 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,122

Rep: Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270Reputation: 2270
just please do not use cat: awk 'script' filename would be better
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
implementation of shift key on keyboard in shell scrpting ngeeta Linux - Newbie 2 02-19-2013 10:42 AM
Negative numbers and decimals kross2100 Linux - Newbie 4 12-07-2012 05:23 PM
Unix scrpting : Append to a file linux_newbee Programming 6 06-12-2006 09:02 AM
How to use decimal numbers in in shell scripts a1ex_007 Programming 6 03-11-2005 10:05 AM
Shell scripting - Adding many numbers in an array Stingreen Linux - General 2 10-25-2004 06:25 PM


All times are GMT -5. The time now is 01:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration