help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: file filtering


From: HS
Subject: Re: file filtering
Date: 31 Jan 2007 04:50:10 -0800
User-agent: G2/1.0

On 31 jan, 05:05, Peter Tury <tury.pe...@gmail.com> wrote:
> "HS" <hug...@gmail.com> writes:
> > Excuse me for saying that here, but do you really need/want to use
> > elisp?
>
> You are right: I don't really need, but I do really want... ;-) More
> precisely: I have an elisp fun what does what I need, but not exactly
> in the way I could really like. So I asked here if it is possible to
> do in some better way or not. From (lack of) early answers it seems:
> not nice way exists :-(
>
> > It seems much easier and "logical" to solve this problem - since
> > it's a command-line script that will do some text processing - with
> > Ruby, Python or Perl.
>
> Yes. Usually. But can exist cases when this would be part of a bigger
> "system" what is "logical to implement" in elisp... Why mix it up with
> other languages if not really needed?

Hm... I can't imagine how "not to read into a buffer"...
I just tried something like this, and it works:

(defun process-file (file)
  (interactive "f")
  (with-temp-buffer
    (insert-file-contents file)
        (delete-non-matching-lines "valid [0-9]+")
        (replace-regexp "valid \\([0-9]+\\)" "I found a \\1" )
        (write-file "test2.txt" nil)))

-------- input file ----------------
blablabla
valid 39
idasuiahsduihas
valid 123
dasuiohdiuahs
dasuiohduahs
dasudhas
valid 29
dasiuhuidah
dasjddij
d
d
asijdsj

-------- output file --------
I found a 39
I found a 123
I found a 29

Don't know if you can use something from that, but anyway :)
Good luck,
HS



reply via email to

[Prev in Thread] Current Thread [Next in Thread]