LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Pattern recognition command (https://www.linuxquestions.org/questions/linux-newbie-8/pattern-recognition-command-402199/)

ghotik 01-11-2006 04:46 PM

Pattern recognition command
 
I have a multi-line file with questionably random number on most of the lines. All other lines are empty. I'm trying to see if there is a pattern in the occurence of these numbers. I imagine I would use something like grep, but I'm not sure, and I want to do this effectively.

Basically I got bored and decided to see if there are any interesting patterns in the occurrences Prime Numbers. Off hand, I can see that most of the numbers of non-primes between each prime is also a prime number. Also these numbers, when finding primes <= 200,000, tend to be small (rarely over 30). Also, primes have a tendency to group in pairs with one non-prime between them. Here is what the first few lines of my file look like (line numbers on the left, number of non-primes between each prime on the right):

1| 0
2| 0
3| 0
4|
5| 1
6|
7| 1
8|
9|
10|
11| 3
12|
13| 1
14|
15|

bosewicht 01-11-2006 04:48 PM

is this homework?? :)

ghotik 01-11-2006 05:07 PM

No, I'm just a code monkey.

pixellany 01-11-2006 06:21 PM

Not a Linux question, IMHO.

In general, you need to methodically take existing patterns and then look for repeats. This will be CPU-intensive.
There are likely many sites full of algorithms for doing this kind of thing. LQ is not one of them.....

ghotik 01-11-2006 06:33 PM

This sounds like a Wayne Graves, RTB.

Anyway, how about we just stick to the question of which command, or more likely command chain, to find patterns in a file.

pixellany 01-11-2006 06:45 PM

Quote:

Originally Posted by ghotik
This sounds like a Wayne Graves, RTB.

Huh??--Is anyone supposed to know what you are talking about?

Searching for patterns:
grep
sed
awk
(for starters)

For one big file full of numbers, I would start with awk and see where that leads you. grep is the simplest, but is line-oriented, and I dont know what it will do with one long file.

More on the format of the file(s) may help us help you more...

ghotik 01-12-2006 09:10 AM

Format on the file:

The file is multi-lined. Each line will either have a number or nothing at all. The corresponding line number of those lines with a number represents a prime number. The number indicates the number of non-primes between this prime, and the last.

bosewicht 01-12-2006 11:42 AM

since you are a code monkey and you are doing it because you are bored, shouldn't you be figuring this out, not have people tell you how to do it?

man grep
man sed
man awk

ghotik 01-13-2006 10:22 AM

Well, you know what they say: a week in the lab will save you an hour in the library. I already know about grep, sed, and awk (gawk), I was just wondering if you guys knew of any neat ways of combining them (or other commands) to discover patterns, but I'll take that as a no. Well, from the looks of it, I'll just have to create a custom pattern recognizer.


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