# 1
09-14-2009

I have a long list of numbers; let's call them integers. Here is an excerpt:

01072523
0371
037408
0382028
038224
01

I want to find integers that contain a certain pattern that I'll describe as a "relationship between adjacent digits".

The pattern is a triplet:

digit digit digit

where:

#1 the relationship between the first and second digit is an increment of at least 3 and

#2 the relationship between the second and third digit is also an increment of at least 3 and

#3 the first digit in the triplet is not at "position 1" in the integer i.e. exclude the first digit of the integer i.e. exclude the first triplet.

Examples:

If integer is 01072523
then two matching triplets

01072523
...^^^

01072523
....^^^

If integer is 037408
then three matching triplets

037408
.^^^

037408
..^^^

037408
...^^^

(The digit at position 1 in the integer 037408 is "0" and the first triplet "037" is excluded from the pattern matching according to rule #3 above.)

If I can use Bourne sh and awk that would be the best.

Cheers!
 uiop44 View Public Profile for uiop44 Find all posts by uiop44
# 2
09-14-2009
what have you tried??
sounds like homework to me
# 3
09-14-2009
Quote:
what have you tried??
sounds like homework to me
I guess I write too much like a professor. I triggered the homework alert.

This can't be homework because I'm not studying Comp Sci or taking any UNIX courses. I already have several degrees; alas none in Maths, Physics, Info Sci or any degree that required it. I am self-taught.

I learn via simple examples, oftentimes from sites like this one.

I must be doing OK if I can write questions that could qualify as UNIX homeworks. Knowing how to ask the right questions is the biggest challenge in learning.

Cheers

Last edited by uiop44; 09-14-2009 at 07:50 PM..
 uiop44 View Public Profile for uiop44 Find all posts by uiop44
# 4
09-14-2009
If it's not homeworks, indeed, it very looks like...any problem can be solved with bash, using any other external program...when you know exactly what it's about...
This is mathematics puzzle to me, and as such I won't be helpful.
It's not undoable: parsing each line of the file, getting for each line what section(s) of it you want to keep, using arithmetics evaluation to compare with what section of the line...

When I see it 'bash coded', I might understand...
...by now, I suggest maintainers/moderators to transfer this post to a more apropriate place such as 'experts...', erasing my message.

wouldn't you?
 daPeach View Public Profile for daPeach Find all posts by daPeach
# 5
09-14-2009
Quote:
Originally Posted by daPeach
If it's not homeworks, indeed, it very looks like...any problem can be solved with bash, using any other external program...when you know exactly what it's about...
This is mathematics puzzle to me, and as such I won't be helpful.
It's not undoable: parsing each line of the file, getting for each line what section(s) of it you want to keep, using arithmetics evaluation to compare with what section of the line...

When I see it 'bash coded', I might understand...
...by now, I suggest maintainers/moderators to transfer this post to a more apropriate place such as 'experts...', erasing my message.

wouldn't you?
Thanks for some perspective dapeach. I'm flattered that you guys think I sound like a UNIX professor.

I was thinking this could be done simply and was just a matter of me not knowing the shell arithmetic functions and use of conditionals.

Perhaps it's more complex than I thought. Maybe it could it be done with string comparison (since there are only so many matching triplet possibilities)?

I'll leave this question up for a few more hours. If no one answers I'll remove it.

I apologise if this question is not really a good one for unix.com (i.e. it wouldn't really be a good learning exercise). I didn't think about it enough. But I did make it sound like a homework assigment... so maybe I get a +1 for writing style.
 uiop44 View Public Profile for uiop44 Find all posts by uiop44
# 6
09-14-2009
OK OK!!!! I agree its not home work question
but i didn't understand how 072 is triplet in 01072523??
you mean 0-7>3 and 7-2>3 {first-sec or sec-first>3}???
if so below code will work.. I know it can be done much smaller way..but for better understanding i wrote like this

Last edited by vidyadhar85; 09-15-2009 at 06:33 PM..
# 7
09-14-2009
Alternatively ksh or bash with a file called 'numbers'
 Scrutinizer View Public Profile for Scrutinizer Find all posts by Scrutinizer

## sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486...

## Find filenames with three digits and add zeros to make five digits

Hello all! I've looked all over the internet and this site and have come up a loss with an easy way to make a bash script to do what I want to do. I have a file with a naming convention as follows: 2012-01-18 string of words here 123.jpg 2012-01-18 string of words here 1234.jpg 2012-01-18...

## Adjacent row and column check in Perl

HI, i am new to perl world. And i am trying to compress a file, as given below procedure. INPUT FILE: 1 1 2 1 ==> R1 2 1 3 1 ==> R2 3 1 4 1 ==> R3 OUTPUT FILE: 1 1 4 1

## help to identify duplicate columns adjacent value

Hi friends, I have a xlsheet like below first column having id ABCfollowed by 7digit numbers and the next column have title against the ids. Titles are unique and duplicateboth, but ids are unique even for duplicate title.Now I need to identify those duplicate title having the highest id for...

## Merging Adjacent Lines Using Gawk

Hi all, I have a text file consisting of 4 columns. What I am trying to do is see whether column 2 repeats multiple times, and collapse those repeats into one row. For example, here is a snippet of the file I am trying to analyze: 1 Gamble_Win 14.282 0.502 1 Sure_Thing 14.858 0.174 1...

## How to calculate the difference between two adjacent columns?

Dear All, I need to find the difference between two adjacent columns. The file is having 'i' columns and i need to find the difference between two adjacent columns (like \$1 difference \$2; \$2 difference \$3; .... and \$(i-1) difference \$i). I have used the following coding awk '{ for (i=1; i<NF;...

## help: single digits inflated to 2 digits

Hi Folks Probably an easy one here but how do I get a sequence to get used as mentioned. For example in the following I want to automatically create files that have a 2 digit number at the end of their names: m@pyhead:~\$ for x in \$(seq 00 10); do touch file_\$x; done m@pyhead:~\$ ls file*...