Compare lines 
Author Message
 Compare lines

Hi

I need to find gaps in a long listing.
Is it possible to make calculations on two lines to find this?

The listing goes like this

340
341
342
343
345 Gap
346
.
.

Thanks in advance
Magne



Sun, 21 Jan 2001 03:00:00 GMT  
 Compare lines


Quote:
>I need to find gaps in a long listing.
>Is it possible to make calculations on two lines to find this?

>The listing goes like this

>340
>341
>342
>343
>345 Gap
>346
>.
>.

If its guarantee'd to be sorted, try
 {if ($1+0 != prev) print "Gap from ", prev, "to" $0
 prev=$1+0}

Untested, but it will give you the idea
Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** See our website at http://www.efiche.com/efiche **



Sun, 21 Jan 2001 03:00:00 GMT  
 Compare lines
: Hi

: I need to find gaps in a long listing.
: Is it possible to make calculations on two lines to find this?

: The listing goes like this

: 340
: 341
: 342
: 343
: 345 Gap
: 346

Simplistic solution.

gawk 'NR==1{x=$1-1}$1!=x+1{print "Gap from "x" to "$1}{x=$1}'

--
See http://www.mauve.demon.co.uk/    |Linux PDA, cheap electronics/PC bits sale.
See_header,_for_UCE_policy___________|_____________________________Ian_Stirling.
"When I use a word," Humpty Dumpty said in a rather scornfull tone, "It means
Just what I choose it to mean - neither more nor less." --    Lewis Carrol



Sun, 21 Jan 2001 03:00:00 GMT  
 Compare lines

Quote:

>>I need to find gaps in a long listing.
>>Is it possible to make calculations on two lines to find this?
>>The listing goes like this
>>340
>>341
>>342
>>343
>>345 Gap
>>346
>>.
>If its guarantee'd to be sorted, try
> {if ($1+0 != prev) print "Gap from ", prev, "to" $0
> prev=$1+0}

Oops I made a typo
While I was at it I included a useful bit of information - namely
the line number (NR). Here is the full program - tested this time!

 {if ($1-1 != prev) print "On line ", NR,"- gap from ", prev, "to " $0
 prev=$1+0}

Mark
--
Mark Katz
ISPC, London - Innovation in data-delivery tools
Tel: (44) 181-455 4665, Fax (44) 181-458 9554
** See our website at http://www.efiche.com/efiche **



Sun, 21 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Q: Compare lines of files

2. Comparing Lines In Awk (Can I do this:)

3. How to compare two files line-by-line

4. assignment and compare on same line?

5. Using EXPECT to compare numerous lines

6. Comparing file objects: what is compared?

7. reversing lines char by char, but not the line order in a file

8. Two lines to one line

9. find a key word and delete 5 lines before it and 5 lines after this

10. Sorting multiple-line data to single line data

11. reading a line and executing a command on that line

12. remove blank lines before lines beginning with string

 

 
Powered by phpBB® Forum Software