Author Topic: Removing Lines from Text File  (Read 8339 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Removing Lines from Text File
« Reply #15 on: January 13, 2010, 03:37:11 PM »
other version...

Code: [Select]
(defun f (a b c) (and a b (write-line b c)))
(defun c:test (/  c d)
 ;; '(nil nil nil t) - Pattern of lines of the text for record
 (setq d (getfiled "Select File" "" "txt" 16)
       c (open (strcat d "-New.txt") "w")
       d (open d "r")
 ) ;_  setq
 (while (foreach a '(nil nil nil t) (f a (read-line d) c)))
 (close d)
 (close c)
) ;_  defun

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Removing Lines from Text File
« Reply #16 on: January 13, 2010, 03:44:32 PM »
Very nice solution Evgeniy, although I think he/she wanted to keep the first line, and discard the rest (other three), so that while loop may need some re-jigging...  :wink:

But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:

« Last Edit: January 13, 2010, 03:52:49 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Removing Lines from Text File
« Reply #17 on: January 13, 2010, 04:01:30 PM »
Yes '(t nil nil nil)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Removing Lines from Text File
« Reply #18 on: January 13, 2010, 04:34:34 PM »
Yes '(t nil nil nil)

Not quite.

The While loop relies on the 't' being last...  :wink:

VovKa

  • Water Moccasin
  • Posts: 1628
  • Ukraine
Re: Removing Lines from Text File
« Reply #19 on: January 13, 2010, 04:41:51 PM »
But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:
i believe Evgeniy has a Kelvinator for "forum-posting" purposes :)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Removing Lines from Text File
« Reply #20 on: January 13, 2010, 04:41:56 PM »
I better have a close look. 8-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Removing Lines from Text File
« Reply #21 on: January 13, 2010, 04:58:44 PM »
I see, very clever.
But this works.
Code: [Select]
(defun f (flag str fn) (and flag str (write-line str fn)))
(defun c:test (/ fname fnr fnw s)
 ;; '(nil nil nil t) - Pattern of lines of the text for record
 (setq fname (getfiled "Select File" "" "txt" 16)
       fnw (open (strcat fname "-New.txt") "w")
       fnr (open fname "r")
 ) ;_  setq
 (while (foreach a '(t nil nil nil) (f a (setq s (read-line fnr)) fnw) s))
 (close fnw)
 (close fnr)
) ;_  defun
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Removing Lines from Text File
« Reply #22 on: January 13, 2010, 05:06:42 PM »
I see, very clever.
But this works.

It does indeed  8-)

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: Removing Lines from Text File
« Reply #23 on: January 13, 2010, 05:27:48 PM »
<snip>
But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:

heh, Dave Stein used to use vowels. *lmao*
(defun blah ( / a e i o u ) ...

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Removing Lines from Text File
« Reply #24 on: January 13, 2010, 05:53:31 PM »
<snip>
But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:

heh, Dave Stein used to use vowels. *lmao*
(defun blah ( / a e i o u ) ...



Haha, reminds me of an article I remember someone posting on here describing 'good programming practices', like having two variables like:

Code: [Select]
(defun blah (/ lI Il ...

And using comments that describe the code as doing something completely different...

trying to find the thread now...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Removing Lines from Text File
« Reply #25 on: January 13, 2010, 05:53:46 PM »
But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:
i believe Evgeniy has a Kelvinator for "forum-posting" purposes :)

 :-)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Removing Lines from Text File
« Reply #26 on: January 13, 2010, 05:56:13 PM »
<snip>
But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:

heh, Dave Stein used to use vowels. *lmao*
(defun blah ( / a e i o u ) ...



Haha, reminds me of an article I remember someone posting on here describing 'good programming practices', like having two variables like:

Code: [Select]
(defun blah (/ lI Il ...

And using comments that describe the code as doing something completely different...

trying to find the thread now...

Ahh yes

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
Re: Removing Lines from Text File
« Reply #27 on: January 13, 2010, 06:18:23 PM »
<snip>
Ahh yes
*click-click* Oh my goodness. yeah dont do that. just put the keyboard down and step away.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Removing Lines from Text File
« Reply #28 on: January 14, 2010, 01:03:45 AM »
But I do wish that you would give you variables some meaningful names... makes it so much easier to follow...  :wink:
i believe Evgeniy has a Kelvinator for "forum-posting" purposes :)

I also am Kelvinator...  8-)

It is convenient me, when local variables short, they do not prevent to see music of the program and its rhythm.
Long names of variables, can borrow more places, than sense the code.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Removing Lines from Text File
« Reply #29 on: January 14, 2010, 07:54:14 AM »
Thanks CAB ... writing to a new text file helps. I just wish I knew  which part of the code to modify if I needed to keep, say every 5th line, 6th line or some other number instead of the 4th.
Is there some kind of pattern you are looking for?
TheSwamp.org  (serving the CAD community since 2003)