[racket] regexp-match to return a line containing a specified string...

From: Danny Yoo (dyoo at hashcollision.org)
Date: Tue May 7 17:43:45 EDT 2013

On Tue, May 7, 2013 at 3:08 PM, Don Green <infodeveloperdon at gmail.com> wrote:
> Trying to use regexp-match to return a line containing a specified string...
>
>
> ;Create fn: find-string.ss.
>
> ;Given a file and a find-string.
>
> ;Returns a line-string with first find.
>
> ;The input file has a lot of lines.


In this case, I would suggest not reading in the whole file in at
once.  Rather, treat the file as a sequence of lines, and use a for
loop to walk across it.  For example, you can do this:


#lang racket
;; Print all the lines in the file "test4.txt"
(for ([line (in-lines (open-input-file "test4.txt"))])
  (printf "~s\n" line))


See the following for more information on sequences, for loops, and
readling line-by-line:

http://docs.racket-lang.org/guide/for.html

http://docs.racket-lang.org/reference/sequences.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._in-lines%29%29

Posted on the users mailing list.