LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 08-19-2011, 03:34 AM   #1
mauludi
LQ Newbie
 
Registered: Jan 2010
Posts: 21

Rep: Reputation: 0
print certain digit only by AWK


Dear All,

for example, mydata.txt :

34.7652 43.0874 87.0977
23.4587 87.9873 98.0986

how to modify this data file using AWK so that first column only consist 2 digit :

34.76 43.0874 87.0977
23.45 87.9873 98.0986

thank you very much in advance

Mauludi
 
Old 08-19-2011, 04:02 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Hi,

Have a look at printf

Code:
$ awk '{ printf("%-.2f %g %g\n", $1, $2, $3 )}' mydata.txt 
34.77 43.0874 87.0977
23.46 87.9873 98.0986
- 5.5 Using printf Statements for Fancier Printing
- 5.5.3 Modifiers for printf Formats

Hope this helps.
 
  


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
Print NaN using awk dhodho Programming 6 06-24-2010 07:05 AM
[SOLVED] Awk - pattern for replace (change digit value) webhope Programming 7 04-26-2010 10:15 PM
[SOLVED] awk print only lines {not}containing FS grail Programming 8 04-12-2010 04:41 AM
How do I - not print - in awk? ZimMonkey Programming 10 08-21-2009 07:11 PM
Substitue single-digit, two-digit, and 3-digit numbers with text using sed dmason165 Programming 13 08-07-2009 10:38 AM


All times are GMT -5. The time now is 12:24 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