File: sed.scm

package info (click to toggle)
snd 26.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 44,044 kB
  • sloc: ansic: 291,996; lisp: 260,569; ruby: 71,134; sh: 3,293; fortran: 2,342; csh: 1,067; cpp: 294; makefile: 294; python: 87; xml: 27; javascript: 1
file content (18 lines) | stat: -rw-r--r-- 511 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

(define (sed in-file out-file source-text dest-text)
  (let ((source-len (length source-text)))
    (call-with-output-file out-file
      (lambda (p)
	(call-with-input-file in-file
	  (lambda (file)
	    (let loop ((line (read-line file)))
	      (or (eof-object? line)
		  (let ((pos (string-position source-text line)))
		    (if pos
			(format p "~A~A~A~%" (substring line 0 pos) dest-text (substring line (+ pos source-len)))
			(format p "~A~%" line))
		    (loop (read-line file)))))))))
    (exit)))