Visit Our UNIX and Linux User Community

Relationships between adjacent digits

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Relationships between adjacent digits
# 8  
Old 09-15-2009
Originally Posted by vidyadhar85
OK OK!!!! I agree its not home work questionSmilie
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 it wrote like thisSmilie
awk '{len=length($0)}{if(len>3){for(i=2;i<=len-2;i++)
if(((sec-first)>=3 || (first-sec)>=3) && ((third-sec)>=3 || (sec-third)>=3)) {print substr($0,i,3)}}}}' filename

This appears to work well. Thank you Tutor! I will pick this apart and no doubt learn some more awk from it.

You're right- 072 should be a matching triplet. I missed it! What I was going to write was "plus or minus greater than or equal to 3" or denote it as "+- >=". Perhaps I could have said "a pos or neg integer that is 3, 4, 5, 6, 7, 8, or 9".

Anyway, I think you understood what I meant.

Also thanks Scrutinzer. My default is actually pdksh v5.2.14 so your ksh script is good to have. I need to not only learn more awk but also more ksh.

I rarely use bash; I use zsh sometimes, e.g. if I need brace expansion.


Last edited by uiop44; 09-15-2009 at 12:11 AM..

Previous Thread | Next Thread
Test Your Knowledge in Computers #5
Difficulty: Easy
The UNIX trademark is a "certification mark".
True or False?

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

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... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: Buzzman25
2 Replies

3. Shell Programming and Scripting

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 (3 Replies)
Discussion started by: vasanth.vadalur
3 Replies

4. UNIX for Dummies Questions & Answers

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... (9 Replies)
Discussion started by: umapearl
9 Replies

5. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: Jahn
4 Replies

6. Shell Programming and Scripting

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;... (7 Replies)
Discussion started by: Fredrick
7 Replies

7. Shell Programming and Scripting

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*... (2 Replies)
Discussion started by: amadain
2 Replies

8. UNIX for Dummies Questions & Answers

print adjacent lines

how do you print the lines before and after the line you are interested in? Example: Line to be printed: line 344 Output: line 343 line 344 line 345 Thanks (1 Reply)
Discussion started by: apalex
1 Replies

Featured Tech Videos