Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Relationships between adjacent digits Post 302353205 by vidyadhar85 on Monday 14th of September 2009 10:14:53 PM
Old 09-14-2009
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 i wrote like thisSmilie
Code:
awk '{len=length($0)}{if(len>3){for(i=2;i<=len-2;i++)
{first=substr($0,i,1);sec=substr($0,i+1,1);third=substr($0,i+2,1);
if(((sec-first)>=3 || (first-sec)>=3) && ((third-sec)>=3 || (sec-third)>=3)) {print substr($0,i,3)}}}}' filename


Last edited by vidyadhar85; 09-15-2009 at 06:33 PM..
 

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
Units(3pm)						User Contributed Perl Documentation						Units(3pm)

NAME
Math::Calc::Units - Human-readable unit-aware calculator SYNOPSIS
use Math::Calc::Units qw(calc readable convert equal); print "It will take ".calc("10MB/(384Kbps)")." to download "; my @alternative_descriptions = readable("10MB/(384Kbps)"); print "A week is ".convert("1 week", "seconds")." long "; if (equal("$rate bytes / sec", "1 MB/sec")) { ... }; DESCRIPTION
"Math::Calc::Units" is a simple calculator that keeps track of units. It currently handles combinations of byte sizes and duration only, although adding any other multiplicative types is easy. Any unknown type is treated as a unique user type (with some effort to map English plurals to their singular forms). The primary intended use is via the "ucalc" script that prints out all of the "readable" variants of a value. For example, "3 bytes" will only produce "3 byte", but "3 byte / sec" produces the original along with "180 byte / minute", "10.55 kilobyte / hour", etc. The "Math::Calc::Units" interface only provides for string-based computations, which could result in a large loss of precision for some applications. If you need the exact result, you may pass in an extra parameter 'exact' to "calc" or "convert", causing them to return a 2-element list containing the numerical result and a string describing the units of that result: my ($value, $units) = convert("10MB/sec", "GB/day"); (In scalar context, they just return the numeric value.) Examples of use o Estimate transmission rates (e.g., 10MB at 384 kilobit/sec) o Estimate performance characteristics (e.g., disk I/O rates) o Figure out how long something will take to complete I tend to work on performance-sensitive code that involves a lot of network and disk traffic, so I wrote this tool after I became very sick of constantly converting KB/sec to GB/day when trying to figure out how long a run is going to take, or what the theoretical maximum performance would be if we were 100% disk bound. Now I can't live without it. Contraindications If you are just trying to convert from one unit to another, you'll probably be better off with "Math::Units" or "Convert::Units". This module really only makes sense when you're converting to and from human-readable values. AUTHOR
Steve Fink <sfink@cpan.org> SEE ALSO
ucalc, Math::Units, Convert::Units. perl v5.10.0 2009-08-04 Units(3pm)
All times are GMT -4. The time now is 12:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy