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 01-01-2010, 12:20 AM   #1
Kilam orez
Member
 
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33

Rep: Reputation: 15
Red face how to count the numerical digits in between the text using a command or a script?


hi dear all,

i want to count the digits in between the text in a file.

e.g.

write down the form

2.3 3.3 3.0 505.0 0.777E-07

22.3 3.3 5.0 503.0 1.777E-04

then read this
.

how can i do the counting of these digits present in between a text in a file?

with regards

kilam
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-01-2010, 01:42 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
what should your total count be? explain in detail how you are counting the digits. Homework?
 
Old 01-01-2010, 02:57 AM   #3
Kilam orez
Member
 
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33

Original Poster
Rep: Reputation: 15
Question

Quote:
Originally Posted by ghostdog74 View Post
what should your total count be? explain in detail how you are counting the digits. Homework?
Actually i have a very big file which contains many points defined by a mathematical function. These point are separated by text, like given in previous thread. But the number of points are very large, more than thousands.

i just want to count the number of points.Also these points are arranged horizontally like given below:

0.135079299943E-03 0.137325385988E-03 0.139599724318E-03 0.141902670302E-03 0.144234583780E-03 0.146595829119E-03 0.148986775268E-03 0.151407795817E-03 and so on.


hope i explained well.

with regards

kilam
 
Old 01-01-2010, 08:31 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
From what you have supplied, it sounds like you want to count NUMBERS and not digits. Each number you show is in scientific notation, which includes a character.

Please clarify exactly what you need to count----for example, in the post above, there are 8 numbers, each with 12 significant digits + a 2-digit exponent. Since the leading digit is always 0, I do not count it as significant.
 
1 members found this post helpful.
Old 01-01-2010, 09:31 AM   #5
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 366Reputation: 366Reputation: 366Reputation: 366
Quote:
i just want to count the number of points.Also these points are arranged horizontally like given below:
So I think he wants to count the total number of numbers.

I expect he could easily do this by counting the total number of occurrences of the letter E as each number has only one E.

Or use tr to convert all the spaces to newlines, grep to filter out blank lines, then just count the number of lines in the file?

Here's an interesting link:
http://www.linuxjournal.com/article/10359

[Edit] It's even easier than that:

The numbers are alphanumeric strings, separated by whitespace. So they count as "words" which can be counted by wc

So to count the number of numbers all you need is wc -w filename

[/Edit]

Last edited by tredegar; 01-01-2010 at 10:45 AM.
 
2 members found this post helpful.
Old 01-02-2010, 04:34 AM   #6
Kilam orez
Member
 
Registered: Aug 2009
Location: India
Distribution: open suse, fedora
Posts: 33

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by tredegar View Post
So I think he wants to count the total number of numbers.

I expect he could easily do this by counting the total number of occurrences of the letter E as each number has only one E.

Or use tr to convert all the spaces to newlines, grep to filter out blank lines, then just count the number of lines in the file?

Here's an interesting link:
http://www.linuxjournal.com/article/10359

[Edit] It's even easier than that:

The numbers are alphanumeric strings, separated by whitespace. So they count as "words" which can be counted by wc

So to count the number of numbers all you need is wc -w filename

[/Edit]
dear tredegar,

sorry i didn't tell that my file contains numbers along with the numbers in scientific notation.
i.e.

-0.968629524999E-01 -0.980905826664E-01 -0.993336540375E-01 -0.100592360821 -0.101866899668

so, counting the number of E's works fine using wc command, but how to count both types of numbers?

with regards,

kilam
 
Old 01-02-2010, 04:57 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
You could count the occurences of the following Regex:
Code:
0\.[0-9]{5}[0-9]*[^0-9]
("0", then literal ".", then a minimum of 5 numerals, then a non-numeral)
 
1 members found this post helpful.
Old 01-02-2010, 05:22 AM   #8
tredegar
Guru
 
Registered: May 2003
Location: London, UK
Distribution: Ubuntu 10.04, mostly
Posts: 6,007

Rep: Reputation: 366Reputation: 366Reputation: 366Reputation: 366
Like I said in my edit - you don't need to count the number of Es. The problem is trivial.

Just use wc -w filename

You could test this by copying a small part of your file to another file, manually counting the numbers, then
wc -w testfile
 
Old 01-02-2010, 05:25 AM   #9
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
Code:
$ more file
text -0.968629524999E-01 -0.980905826664E-01 -0.993336540375E-01 -0.100592360821 -0.101866899668 text
$ awk '{for(o=1;o<=NF;o++)if($o+0==$o) ++d}END{print d}' file
5
 
1 members found this post helpful.
Old 01-03-2010, 12:15 AM   #10
sonu kumar
LQ Newbie
 
Registered: Aug 2009
Location: India
Distribution: open suse
Posts: 28

Rep: Reputation: 17
Quote:
Originally Posted by tredegar View Post
Like I said in my edit - you don't need to count the number of Es. The problem is trivial.

Just use wc -w filename

You could test this by copying a small part of your file to another file, manually counting the numbers, then
wc -w testfile
thank you
 
  


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
Text file manipulation: Extracting specific rows according to numerical pattern CHARL0TTE Linux - Newbie 3 10-07-2009 07:14 AM
BASH - convert single digits to double digits. rickenbacherus Programming 7 05-07-2008 06:53 AM
bash script to preserve only first digits alenD Linux - Software 6 04-14-2008 12:51 PM
count digits of a float || convert float to string nadroj Programming 6 07-11-2005 04:52 PM
Latest Kernel script on front page, does it need to be updated to accept four digits? SBing LQ Suggestions & Feedback 1 09-09-2004 12:35 PM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration