LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-11-2006, 05:46 PM   #1
ghotik
LQ Newbie
 
Registered: Jan 2006
Posts: 5

Rep: Reputation: 0
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|
 
Old 01-11-2006, 05:48 PM   #2
bosewicht
Senior Member
 
Registered: Aug 2003
Location: Honolulu, HI
Distribution: Arch
Posts: 1,380

Rep: Reputation: 47
is this homework??
 
Old 01-11-2006, 06:07 PM   #3
ghotik
LQ Newbie
 
Registered: Jan 2006
Posts: 5

Original Poster
Rep: Reputation: 0
No, I'm just a code monkey.
 
Old 01-11-2006, 07:21 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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.....
 
Old 01-11-2006, 07:33 PM   #5
ghotik
LQ Newbie
 
Registered: Jan 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 01-11-2006, 07:45 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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...
 
Old 01-12-2006, 10:10 AM   #7
ghotik
LQ Newbie
 
Registered: Jan 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
Old 01-12-2006, 12:42 PM   #8
bosewicht
Senior Member
 
Registered: Aug 2003
Location: Honolulu, HI
Distribution: Arch
Posts: 1,380

Rep: Reputation: 47
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
 
Old 01-13-2006, 11:22 AM   #9
ghotik
LQ Newbie
 
Registered: Jan 2006
Posts: 5

Original Poster
Rep: Reputation: 0
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.

Last edited by ghotik; 01-13-2006 at 11:24 AM.
 
  


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
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 07:17 AM
singleton pattern in C++? Thinking Programming 7 11-13-2005 08:45 PM
pattern search through find command. abhi Linux - Newbie 2 04-11-2005 11:31 AM
using grep when the pattern contains a ! farmerjoe Programming 9 03-16-2005 12:04 AM
Pattern Recognition trbdk3 Linux - Software 1 01-27-2005 02:13 PM


All times are GMT -5. The time now is 10:43 AM.

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