(use irregex posix srfi-13 utils) (define file "your-file") (define index "index") ; bos = beggining of string (define byte-num-regexp '(: bos (* num))) (define (get-byte-offset line) (car (irregex-extract byte-num-regexp line))) (define (grep-output file) (call-with-values (lambda () (process (string-append "grep -b '' " file))) (lambda (in-port _ _) (read-all in-port)))) (define (make-index grep-output) (let ((index-fileno (file-open index (+ open/wronly open/append open/creat)))) (with-input-from-string grep-output (lambda () (let loop ((line (read-line))) (unless (eof-object? line) (file-write index-fileno (string-append (string-pad (get-byte-offset line) 16) "\n")) (loop (read-line)))))))) (define (start-index) (make-index (grep-output file)))