Finding a text in raw data(size nearly 10GB) and Printing its memory address using python

bartc bc at freeuk.com
Mon Apr 23 16:52:18 EDT 2018


On 23/04/2018 21:45, Stefan Ram wrote:
> MRAB <python at mrabarnett.plus.com> writes:
>> offset += search_length
> 
>    Or, offset += 1, to also find overlaps of that kind:
> 
> file = "eee"
> word = "ee"
> 
>    . The above word "ee" occurs at position 0 and 1 in the file.
> 
>    My attempt:
> 
> #include <stdio.h>
> #include <string.h>
> int main( void )
> { FILE * const haystack = fopen( "filename.dmp", "r" );
>    if( !haystack )goto end;
>    char const * const needle = "bd:mongo:";
>    int offset = 0;
>    int const l =( int )strlen( needle );
>    { int o[ l ]; /* VLA */
>      for( int i=0; i < l; ++i )o[ i ]= -1;
>      o[ 0 ]= 0;
>      next: ;
>      int const x = fgetc( haystack );
>      if( x == EOF )goto out;
>      ++offset;
>      for( int i=0; i < l; ++ i )
>      if( o[ i ]>= 0 )
>      { char const ch = needle[ o[ i ] ];
>        if( ch == x )++o[ i ];
>        if( o[ i ]==( int )strlen( needle ))
>        { printf( "found at %d\n", offset -( int )strlen( needle )); }}
>      for( int i = l; i; --i )o[ i ]= o[ i - 1 ];
>      o[ 0 ]= 0;
>      goto next;
>      out: fclose( haystack ); }
>    end: ; }
> 

Did you say that you teach programming?

-- 
bartc



More information about the Python-list mailing list