http://technoninja.blogspot.com/2011/03/pick-ip-out-of-big-ugly-text-fiel-using.html
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/15/2011 8:54:17 AM |
|
(the troll gavino) ; wrote:
;;> http://technoninja.blogspot.com/2011/03/pick-ip-out-of-big-ugly-text-fiel-using.html
(declare (ignorable gavino))
(go away)
|
|
0
|
|
|
|
Reply
|
norbertpauls_spambin (117)
|
3/15/2011 9:42:10 AM
|
|
I am going to try to.
wizards please post an implementation in clisp preferably
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/15/2011 11:39:12 AM
|
|
gavino <gavcomedy@gmail.com> writes:
> wizards please post an implementation in clisp preferably
Why don't you ask the wizard for a brain, scarecrow?
--
(espen)
|
|
0
|
|
|
|
Reply
|
espen1 (438)
|
3/15/2011 12:10:43 PM
|
|
The tcl program contains this:
#pick out ips on 144 network such as 144.123.123.123 etc. and write them to
result file
foreach rec $records {
if {[string match {144*[1-9]} $rec]} {
puts $chan $rec
Obviously, "144*[1-9]" is a botched regular expression.
It should be something like "^144\.[0-9]".
MatzLisp (Ruby):
# Read file and split on whitespace.
records = IO.read( "data1.txt" ).split
# Write matching records.
open("out.txt", "w"){|file|
file.puts records.grep( /^144(\.\d+){3}$/ )}
|
|
0
|
|
|
|
Reply
|
w_a_x_man (2778)
|
3/15/2011 1:38:00 PM
|
|
Finally! We've got the trolls feeding on each other. Maybe froggy will
join in and the three can troll each other into eternity.
warmest regards,
Ralph
--
Raffael Cavallaro
|
|
0
|
|
|
|
Reply
|
raffaelcavallaro6342 (133)
|
3/15/2011 8:18:34 PM
|
|
Raffael Cavallaro <raffaelcavallaro@pas.despam.s.il.vous.plait.mac.com>
writes:
> Finally! We've got the trolls feeding on each other. Maybe froggy will
> join in and the three can troll each other into eternity.
Thanks to keep us up to date about people we've kill filed.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|
|
0
|
|
|
|
Reply
|
pjb (7645)
|
3/15/2011 9:53:02 PM
|
|
On Mar 15, 2:42=A0am, Norbert_Paul <norbertpauls_spam...@yahoo.com>
wrote:
> (the troll gavino) ; wrote:
> ;;>http://technoninja.blogspot.com/2011/03/pick-ip-out-of-big-ugly-text-.=
...
> (declare (ignorable gavino))
> (go away)
who are you?
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/16/2011 8:34:07 AM
|
|
On Mar 15, 5:10=A0am, Espen Vestre <es...@vestre.net> wrote:
> gavino <gavcom...@gmail.com> writes:
> > wizards please post an implementation in clisp preferably
>
> Why don't you ask the wizard for a brain, scarecrow?
> --
> =A0 (espen)
who are you?
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/16/2011 8:34:12 AM
|
|
On Mar 15, 1:18=A0pm, Raffael Cavallaro
<raffaelcavall...@pas.despam.s.il.vous.plait.mac.com> wrote:
> Finally! We've got the trolls feeding on each other. Maybe froggy will
> join in and the three can troll each other into eternity.
>
> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro
who are you?
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/16/2011 8:34:55 AM
|
|
On Mar 15, 6:38=A0am, "WJ" <w_a_x_...@yahoo.com> wrote:
> The tcl program contains this:
>
> #pick out ips on 144 network such as 144.123.123.123 etc. and write them =
to
> result file
> foreach rec $records {
> if {[string match {144*[1-9]} $rec]} {
> puts $chan $rec
>
> Obviously, "144*[1-9]" is a botched regular expression.
> It should be something like "^144\.[0-9]".
>
> MatzLisp (Ruby):
>
> # Read file and split on whitespace.
> records =3D IO.read( "data1.txt" ).split
> # Write matching records.
> open("out.txt", "w"){|file|
> =A0 file.puts records.grep( /^144(\.\d+){3}$/ )}
#!/usr/local/bin/tclsh
## Read the file
set handle [open 144a]
set gunk [read $handle]
close $handle
## Split into records on 1 blank space
set words [split $gunk " "]
#open result file
set outpipe [open servers a]
#pick out ips on 144 tila network
# write them to result file
set boxes [lsort -unique [lsearch -all -inline $words {144*[1-9]}]]
puts $outpipe $boxes
#close result file
close $outpipe
I updated this but someone pointed out that 144.bla.bla.30 would not
be picked up. yikes I was sloppy.
I opened hyperspec and pcl and successful by lamkins and got
frustrated trying to figure this out even in common lisp.
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/16/2011 8:42:31 AM
|
|
; I think this does what you are looking for.
; There are Common Lisp libraries for splitting strings and
; doing regular expressions, but this
; does not require any additional packages to be installed.
(defun linespace?(char)
(or (char= char #\Tab)
(char= char #\Space)))
(defun string-starts-with (string substring)
(let ()
(cond
((< (length string) (length substring))
nil)
( (string= substring (subseq string 0 (length substring)) )
t))))
(defun split-by-whitespace (string)
(let* (
(STARTING 0)
(TOKEN 1)
(WHITESPACE 2)
(state STARTING)
(a-token "")
(the-list '() )
(str-length (length string)) )
(dotimes (i str-length)
(if (linespace? (char string i))
(progn
(if (eq state TOKEN)
(progn
(setq the-list (cons a-token the-list))
(setq a-token "")))
(setq state WHITESPACE))
(progn
(setq a-token
(concatenate 'string a-token (string (char string
i))))
(setq state TOKEN))))
(if (eq state TOKEN)
(setq the-list (cons a-token the-list)))
(setq the-list (reverse the-list))))
(defun process-file(input-filename output-filename ip-address-start)
(let ( (input-line "")
(input-file nil)
(output-file nil)
(line-tokens '())
(counter 0))
(when (not (probe-file input-filename))
(format t "ERROR: ~s does not exist~%" input-filename)
(return-from process-file 1))
(setq input-file (open input-filename))
(setq output-file
(open output-filename :direction :output :if-
exists :supersede))
(setq input-line (read-line input-file nil))
(loop
(if (null input-line) (return))
(setq counter (+ counter 1))
; next line is fix for SBCL Windows bug
(setq input-line (string-right-trim '(#\Return) input-
line))
(setq line-tokens (split-by-whitespace input-line))
(dolist (token line-tokens)
(when (string-starts-with token ip-address-start)
(format output-file "~a~%" token)))
(setq input-line (read-line input-file nil)))
(close input-file)
(close output-file)))
(defvar *input-filename* "my_input_file.txt")
(defvar *output-filename* "my_output_file.txt")
(defvar *ip-address-start* "144.")
(process-file *input-filename* *output-filename* *ip-address-start*)
|
|
0
|
|
|
|
Reply
|
zzbbaadd (349)
|
3/16/2011 10:13:54 AM
|
|
gavino <gavcomedy@gmail.com> writes:
> On Mar 15, 1:18 pm, Raffael Cavallaro
> <raffaelcavall...@pas.despam.s.il.vous.plait.mac.com> wrote:
>> Finally! We've got the trolls feeding on each other. Maybe froggy will
>> join in and the three can troll each other into eternity.
>>
>> warmest regards,
>>
>> Ralph
>>
>> --
>> Raffael Cavallaro
>
> who are you?
I suspect that Raffael Cavallaro is Raffael Cavallaro. I further suspect
that "gavino" is "technoninja" is "dollar_democrat" - "dollar_democrat"
appears as the signature on the post on the "technoninja" blog, and the
code on the blog is as helplessly clueless as the code that we have seen
from gavino earlier.
It's a sad thing that most of the code posted to cll these days is
small snippets of good (or even great) lisp code posted as responses to
code that is either off-topic, bad or both... (Xah, W.J. and gavino -
I'm looking at *you*.)
|
|
0
|
|
|
|
Reply
|
raw2965 (44)
|
3/16/2011 3:18:27 PM
|
|
In article
<9e32e955-6660-4e5f-a478-827b28691339@r4g2000prm.googlegroups.com>,
gavino <gavcomedy@gmail.com> wrote:
> On Mar 15, 5:10 am, Espen Vestre <es...@vestre.net> wrote:
> > gavino <gavcom...@gmail.com> writes:
> > > wizards please post an implementation in clisp preferably
> >
> > Why don't you ask the wizard for a brain, scarecrow?
> > --
> > (espen)
>
> who are you?
Who are you?
Who, who, who, who?
Who are you?
Who, who, who, who?
Who are you?
Who, who, who, who?
Who are you?
Who, who, who, who?
I woke up in a Soho doorway
A policeman knew my name
He said "You can go sleep at home tonight
If you can get up and walk away"
I staggered back to the underground
And the breeze blew back my hair
I remember throwin' punches around
And preachin' from my chair
chorus:
Well, who are you? (Who are you? Who, who, who, who?)
I really wanna know (Who are you? Who, who, who, who?)
Tell me, who are you? (Who are you? Who, who, who, who?)
'Cause I really wanna know (Who are you? Who, who, who, who?)
I took the tube back out of town
Back to the Rollin' Pin
I felt a little like a dying clown
With a streak of Rin Tin Tin
I stretched back and I hiccupped
And looked back on my busy day
Eleven hours in the Tin Pan
God, there's got to be another way
Who are you?
Ooh wa ooh wa ooh wa ooh wa ...
Who are you?
Who, who, who, who?
Who are you?
Who, who, who, who?
Who are you?
Who, who, who, who?
Who are you?
Who, who, who, who?
(chorus)
I know there's a place you walked
Where love falls from the trees
My heart is like a broken cup
I only feel right on my knees
I spit out like a sewer hole
Yet still recieve your kiss
How can I measure up to anyone now
After such a love as this?
(chorus)
|
|
0
|
|
|
|
Reply
|
rNOSPAMon (1855)
|
3/16/2011 4:27:37 PM
|
|
On Mar 16, 7:13=A0am, TheFlyingDutchman <zzbba...@aol.com> wrote:
> (defun split-by-whitespace (string)
> =A0 (let* (
> =A0 =A0 =A0 =A0 =A0(STARTING 0)
> =A0 =A0 =A0 =A0 =A0(TOKEN 1)
> =A0 =A0 =A0 =A0 =A0(WHITESPACE 2)
> =A0 =A0 =A0 =A0 =A0(state STARTING)
> =A0 =A0 =A0 =A0 =A0(a-token "")
> =A0 =A0 =A0 =A0 =A0(the-list '() )
> =A0 =A0 =A0 =A0 =A0(str-length (length string)) )
> =A0 =A0(dotimes (i str-length)
> =A0 =A0 =A0(if (linespace? (char string i))
> =A0 =A0 =A0 =A0 =A0(progn
> =A0 =A0 =A0 =A0 =A0 =A0(if (eq state TOKEN)
> =A0 =A0 =A0 =A0 =A0 =A0 (progn
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq the-list (cons a-token the-list))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq a-token "")))
> =A0 =A0 =A0 =A0 =A0 =A0(setq state WHITESPACE))
> =A0 =A0 =A0 =A0 =A0(progn
> =A0 =A0 =A0 =A0 =A0 =A0(setq a-token
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (concatenate 'string a-token (string (cha=
r string
> i))))
> =A0 =A0 =A0 =A0 =A0 =A0(setq state TOKEN))))
> =A0 =A0(if (eq state TOKEN)
> =A0 =A0 =A0(setq the-list (cons a-token the-list)))
> =A0 =A0(setq the-list (reverse the-list))))
besides biting the troll, why not a generalized split function
instead?
for instance, I have this in my personal scheme lib:
(define (split txt . seps)
; aliases and convenient functions
(let* ((ss (if (null? seps) #\space seps))
(sz (string-length txt))
(break? (if (pair? seps)
(lambda (i)
(pair? (memq (string-ref txt (- i 1)) seps)))
(lambda (i)
(char=3D? ss (string-ref txt (- i 1))))))
(result (lambda (i end r)
(if (< i end) (cons (cons i end) r) r))))
; core functionality
(let lp ((i sz) (end sz) (r '()))
(cond ((=3D i 0) (result i end r))
((break? i) (lp (- i 1) (- i 1) (result i end r)))
(#t (lp (- i 1) end r))))))
; testing:
(split "foobar was here, just yesterday!")
; =3D> ((0 . 6) (7 . 10) (11 . 16) (17 . 21) (22 . 32))
; it gives indexes for substring, so:
(let ((txt "foobar was here, just yesterday!"))
(map (lambda (i) (substring txt (car i) (cdr i)))
(split txt #\space #\, #\!)))
; =3D> ("foobar" "was" "here" "just" "yesterday")
|
|
0
|
|
|
|
Reply
|
namekuseijin (629)
|
3/16/2011 5:10:48 PM
|
|
namekuseijin <namekuseijin@gmail.com> writes:
> besides biting the troll, why not a generalized split function
> instead?
>
> for instance, I have this in my personal scheme lib:
>
> (define (split txt . seps)
Because this is not comp.lang.scheme, for example.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|
|
0
|
|
|
|
Reply
|
pjb (7645)
|
3/16/2011 5:26:12 PM
|
|
On Mar 16, 2:26=A0pm, "Pascal J. Bourguignon" <p...@informatimago.com>
wrote:
> namekuseijin <namekusei...@gmail.com> writes:
> > besides biting the troll, why not a generalized split function
> > instead?
>
> > for instance, I have this in my personal scheme lib:
>
> > (define (split txt . seps)
>
> Because this is not comp.lang.scheme, for example.
I'm sure you're not implying split in CL should be that constrained...
but this is off-topic in this off-topic troll thread...
|
|
0
|
|
|
|
Reply
|
namekuseijin (629)
|
3/16/2011 5:50:04 PM
|
|
On Mar 15, 6:10=A0am, Espen Vestre <es...@vestre.net> wrote:
> gavino <gavcom...@gmail.com> writes:
> > wizards please post an implementation in clisp preferably
>
> Why don't you ask the wizard for a brain, scarecrow?
> --
> =A0 (espen)
I think you guys should cut Gavino some slack. He does troll in the
sense that he posts on multiple forums (like a fisherman running
multiple lines behind his boat in order to increase his chance of
getting a bite). Gavino does *not* insult people however. He has never
told me that my code "sucks" or that I "pulled it out of my ass" or
that I am "diseased" --- all of which has been said to me by others
(according to the self-appointed experts of c.l.f., every line of
Forth I've ever written has sucked). Gavino is positive though, always
asking if Forth could be used for some grandiose project (yes it
could, but work would be required). It is still nonsense, but at least
it is nice nonsense. I'm all for kill-listing trolls who tell
programmers that their code sucks, without writing any code of their
own --- but Gavino isn't one of these --- and neither is Mentifex, who
I have also offered to help in regard to Forth programming.
I have told Gavino in the past that he needs to start writing some
code, and that I will help him as much as I can when he does. I told
him the same thing again when he posted his IP-recognition question on
comp.lang.forth:
http://groups.google.com/group/comp.lang.forth/browse_thread/thread/bb39b0a=
afa65a653#
You guys could say as much in regard to Lisp.
I've never written any non-trivial Lisp code myself, and yet I have
posted messages on comp.lang.lisp on several occasions. I could be
called a troll too! I don't consider myself a troll though, because I
don't claim to be a leading expert on Lisp, and I don't insult people
who do write Lisp code. I'll likely get going on the Lisp one of these
days. It is difficult to build up any enthusiasm for programming
though, when I know that the only result will be to have people tell
me that my code sucks.
|
|
0
|
|
|
|
Reply
|
hughaguilar96 (1076)
|
3/16/2011 10:21:48 PM
|
|
On Mar 16, 11:10=A0am, namekuseijin <namekusei...@gmail.com> wrote:
> besides biting the troll, why not a generalized split function
> instead?
>
> for instance, I have this in my personal scheme lib:
>
> (define (split txt . seps)
Since off-topic posts are the order of the day, here is my Forth
version from my novice package (http://www.forth.org/novice.html). The
Forth code is more powerful than the Scheme version, in that it allows
quoted strings within the fields. It seems more readable too, but that
may just be because I don't know Scheme very well.
: <split> { adr cnt delimiter left right | lit-str? -- head }
nil <cstr
adr cnt + adr ?do \ -- head
lit-str? if
I c@ right =3D if false to lit-str?
else I c@ char+cstr then
else
I c@ delimiter =3D if
cstr> new-seq link \ -- new-head
<cstr
else
I c@ left =3D if true to lit-str?
else I c@ char+cstr then
then
then
loop
cstr> dup c@ if new-seq link
else drop then ;
vector split ( adr cnt -- head )
: comma-split ( adr cnt -- head )
[char] , [char] " [char] " <split> ;
' comma-split is-split
The left and right chars are for bracketing quoted strings inside of
the fields. If the field delimiter appears inside of a quoted string,
the line doesn't get split there.
|
|
0
|
|
|
|
Reply
|
hughaguilar96 (1076)
|
3/16/2011 11:38:37 PM
|
|
On Mar 16, 3:13=A0am, TheFlyingDutchman <zzbba...@aol.com> wrote:
> ; I think this does what you are looking for.
> ; There are Common Lisp libraries for splitting strings and
> ; doing regular expressions, but this
> ; does not require any additional packages to be installed.
>
> (defun linespace?(char)
> =A0 (or (char=3D char #\Tab)
> =A0 =A0 =A0 (char=3D char #\Space)))
>
> (defun string-starts-with (string substring)
> =A0 (let ()
> =A0 =A0 =A0(cond
> =A0 =A0 =A0 =A0((< (length string) (length substring))
> =A0 =A0 =A0 =A0 =A0nil)
> =A0 =A0 =A0 =A0( (string=3D substring (subseq string 0 (length substring)=
) )
> =A0 =A0 =A0 =A0 =A0t))))
>
> (defun split-by-whitespace (string)
> =A0 (let* (
> =A0 =A0 =A0 =A0 =A0(STARTING 0)
> =A0 =A0 =A0 =A0 =A0(TOKEN 1)
> =A0 =A0 =A0 =A0 =A0(WHITESPACE 2)
> =A0 =A0 =A0 =A0 =A0(state STARTING)
> =A0 =A0 =A0 =A0 =A0(a-token "")
> =A0 =A0 =A0 =A0 =A0(the-list '() )
> =A0 =A0 =A0 =A0 =A0(str-length (length string)) )
> =A0 =A0(dotimes (i str-length)
> =A0 =A0 =A0(if (linespace? (char string i))
> =A0 =A0 =A0 =A0 =A0(progn
> =A0 =A0 =A0 =A0 =A0 =A0(if (eq state TOKEN)
> =A0 =A0 =A0 =A0 =A0 =A0 (progn
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq the-list (cons a-token the-list))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq a-token "")))
> =A0 =A0 =A0 =A0 =A0 =A0(setq state WHITESPACE))
> =A0 =A0 =A0 =A0 =A0(progn
> =A0 =A0 =A0 =A0 =A0 =A0(setq a-token
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (concatenate 'string a-token (string (cha=
r string
> i))))
> =A0 =A0 =A0 =A0 =A0 =A0(setq state TOKEN))))
> =A0 =A0(if (eq state TOKEN)
> =A0 =A0 =A0(setq the-list (cons a-token the-list)))
> =A0 =A0(setq the-list (reverse the-list))))
>
> (defun process-file(input-filename output-filename ip-address-start)
> =A0 (let ( =A0 (input-line "")
> =A0 =A0 =A0 =A0 =A0 =A0(input-file nil)
> =A0 =A0 =A0 =A0 =A0 =A0(output-file nil)
> =A0 =A0 =A0 =A0 =A0 =A0(line-tokens '())
> =A0 =A0 =A0 =A0 =A0 =A0(counter 0))
> =A0 =A0 =A0(when (not (probe-file input-filename))
> =A0 =A0 =A0 =A0 (format t "ERROR: ~s does not exist~%" input-filename)
> =A0 =A0 =A0 =A0 (return-from process-file 1))
> =A0 =A0 =A0(setq input-file (open input-filename))
> =A0 =A0 =A0(setq output-file
> =A0 =A0 =A0 =A0 (open output-filename :direction :output :if-
> exists :supersede))
> =A0 =A0 =A0(setq input-line (read-line input-file nil))
> =A0 =A0 =A0(loop
> =A0 =A0 =A0 =A0 =A0 =A0(if (null input-line) (return))
> =A0 =A0 =A0 =A0 =A0 =A0(setq counter (+ counter 1))
> =A0 =A0 =A0 =A0 =A0 =A0; next line is fix for SBCL Windows bug
> =A0 =A0 =A0 =A0 =A0 =A0(setq input-line (string-right-trim '(#\Return) in=
put-
> line))
> =A0 =A0 =A0 =A0 =A0 =A0(setq line-tokens (split-by-whitespace input-line)=
)
> =A0 =A0 =A0 =A0 =A0 =A0(dolist (token line-tokens)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(when (string-starts-with token ip-address-sta=
rt)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(format output-file "~a~%" token)))
> =A0 =A0 =A0 =A0 =A0 =A0(setq input-line (read-line input-file nil)))
> =A0 =A0 =A0(close input-file)
> =A0 =A0 =A0(close output-file)))
>
> (defvar *input-filename* "my_input_file.txt")
> (defvar *output-filename* "my_output_file.txt")
> (defvar *ip-address-start* "144.")
>
> (process-file *input-filename* *output-filename* *ip-address-start*)
holy shit awesome!!!
HEre was my final tcl version:
#!/usr/local/bin/tclsh
# tcl 8.5.9 used
## Read the file
set handle [open 144a]
set gunk [read $handle]
close $handle
## Split into records on 1 blank space
set words [split $gunk " "]
#pick out ips on 144 tila network
set boxes [lsort -unique [lsearch -all -inline $words {144*[0-9]}]]
#remove ips with .0 on the end, network names
set nozero [lsearch -all -inline -not $boxes {*\.0}]
#open result file
set outpipe [open grabip5results a]
# write ips to result file, one per line
foreach ip $nozero {
puts $outpipe $ip
}
#close result file
close $outpipe
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/17/2011 1:19:33 AM
|
|
TheFlyingDutchman <zzbbaadd@aol.com> writes:
> ; I think this does what you are looking for.
> ; There are Common Lisp libraries for splitting strings and
> ; doing regular expressions, but this
> ; does not require any additional packages to be installed.
>
This version uses only cl-ppcre:
(defun grep (pattern &optional (input-stream *standard-input*) (output-stream *standard-output*))
(let ((matcher (cl-ppcre:create-scanner pattern)))
(loop for line = (read-line input-stream nil nil)
while line
do (dolist (token (cl-ppcre:split "\\s+" line))
(when (cl-ppcre:scan matcher token)
(write-line token output-stream))))))
#||
(with-input-from-string (s "this is a test 144.125.192.168 144.abc.125.168 144.1.2.3")
(grep "^144(\\.[0-9]{1,3}){3}$" s))
||#
|
|
0
|
|
|
|
Reply
|
raw2965 (44)
|
3/17/2011 6:01:23 AM
|
|
On Mar 16, 11:01=A0pm, Raymond Wiker <r...@RAWMBP-2.local> wrote:
> TheFlyingDutchman <zzbba...@aol.com> writes:
> > ; I think this does what you are looking for.
> > ; There are Common Lisp libraries for splitting strings and
> > ; doing regular expressions, but this
> > ; does not require any additional packages to be installed.
>
> This version uses only cl-ppcre:
>
> (defun grep (pattern &optional (input-stream *standard-input*) (output-st=
ream *standard-output*))
> =A0 (let ((matcher (cl-ppcre:create-scanner pattern)))
> =A0 =A0 (loop for line =3D (read-line input-stream nil nil)
> =A0 =A0 =A0 =A0 =A0 while line
> =A0 =A0 =A0 =A0 =A0 do (dolist (token (cl-ppcre:split "\\s+" line))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(when (cl-ppcre:scan matcher token)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(write-line token output-stream))))))
>
> #||
> (with-input-from-string (s "this is a test 144.125.192.168 144.abc.125.16=
8 144.1.2.3")
> =A0(grep "^144(\\.[0-9]{1,3}){3}$" s))
> ||#
woa
can you add the open file part and close file part?
nice
I will have t try this and the dutchmans tomorrow.
thank you
|
|
0
|
|
|
|
Reply
|
gavcomedy (1610)
|
3/17/2011 10:57:29 AM
|
|
Hugh Aguilar <hughaguilar96@yahoo.com> writes:
> On Mar 15, 6:10�am, Espen Vestre <es...@vestre.net> wrote:
>> gavino <gavcom...@gmail.com> writes:
>> > wizards please post an implementation in clisp preferably
>>
>> Why don't you ask the wizard for a brain, scarecrow?
>> --
>> � (espen)
>
> I think you guys should cut Gavino some slack.
I was hoping someone would appreciate my Wizard of Oz-reference
here...
--
(espen)
|
|
0
|
|
|
|
Reply
|
espen1 (438)
|
3/17/2011 11:52:01 AM
|
|
On Mar 17, 11:57=A0am, gavino <gavcom...@gmail.com> wrote:
> On Mar 16, 11:01=A0pm, Raymond Wiker <r...@RAWMBP-2.local> wrote:
>
>
>
>
>
>
>
>
>
> > TheFlyingDutchman <zzbba...@aol.com> writes:
> > > ; I think this does what you are looking for.
> > > ; There are Common Lisp libraries for splitting strings and
> > > ; doing regular expressions, but this
> > > ; does not require any additional packages to be installed.
>
> > This version uses only cl-ppcre:
>
> > (defun grep (pattern &optional (input-stream *standard-input*) (output-=
stream *standard-output*))
> > =A0 (let ((matcher (cl-ppcre:create-scanner pattern)))
> > =A0 =A0 (loop for line =3D (read-line input-stream nil nil)
> > =A0 =A0 =A0 =A0 =A0 while line
> > =A0 =A0 =A0 =A0 =A0 do (dolist (token (cl-ppcre:split "\\s+" line))
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(when (cl-ppcre:scan matcher token)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(write-line token output-stream)))))=
)
>
> > #||
> > (with-input-from-string (s "this is a test 144.125.192.168 144.abc.125.=
168 144.1.2.3")
> > =A0(grep "^144(\\.[0-9]{1,3}){3}$" s))
> > ||#
>
> woa
> can you add the open file part and close file part?
> nice
> I will have t try this and the dutchmans tomorrow.
> thank you
(with-open-file (in "the-file.txt" :direction :input)
(with-open-file (out "my-output.txt" :direction :output)
(grep "^144(\\.[0-9]{1,3}){3}$" in out)))
Cheers
--
Marco
|
|
0
|
|
|
|
Reply
|
marcoxa1 (977)
|
3/17/2011 3:27:43 PM
|
|
On 2011-03-17 07:52:01 -0400, Espen Vestre said:
> I was hoping someone would appreciate my Wizard of Oz-reference
> here...
oh, we got the reference all right:
If Gavino Had a Brain
(to the tune of "If I Only Had a Brain")
He could while away the hours,
With lisp's numerical tower,
Programming unchained
No problems would he be posing
Just parens neatly closing
If Gavino had a brain
He'd avoid a Usenet roasting
By cutting out his posting
Of questions asked in vain
He'd no longer be a slacker
He would be a true lisp hacker
If Gavino had a brain
Oh he, would surely be, an s-expression pro
He would know where all the lambda list keywords go
And he could write, a fine macro!
He would not be merely trolling
And setting our eyes rolling
Another Usenet stain
No more a newsgroup retard
He would be a true lisp wizard
If Gavino had a brain!
warmest regards,
Ralph
--
Raffael Cavallaro
|
|
0
|
|
|
|
Reply
|
raffaelcavallaro6342 (133)
|
3/17/2011 3:45:29 PM
|
|
Raffael Cavallaro <raffaelcavallaro@pas.despam.s.il.vous.plait.mac.com>
writes:
> If Gavino Had a Brain
> (to the tune of "If I Only Had a Brain")
LOL :-)
--
(espen)
|
|
0
|
|
|
|
Reply
|
espen1 (438)
|
3/17/2011 4:41:01 PM
|
|
On Mar 17, 8:52=A0am, Espen Vestre <es...@vestre.net> wrote:
> Hugh Aguilar <hughaguila...@yahoo.com> writes:
> > On Mar 15, 6:10 am, Espen Vestre <es...@vestre.net> wrote:
> >> gavino <gavcom...@gmail.com> writes:
> >> > wizards please post an implementation in clisp preferably
>
> >> Why don't you ask the wizard for a brain, scarecrow?
> >> --
> >> (espen)
>
> > I think you guys should cut Gavino some slack.
>
> I was hoping someone would appreciate my Wizard of Oz-reference
> here...
it was very fine. :)
|
|
0
|
|
|
|
Reply
|
namekuseijin (629)
|
3/17/2011 5:30:16 PM
|
|
Hugh Aguilar wrote:
> On Mar 15, 6:10�am, Espen Vestre <es...@vestre.net> wrote:
> > gavino <gavcom...@gmail.com> writes:
> > > wizards please post an implementation in clisp preferably
> >
> > Why don't you ask the wizard for a brain, scarecrow?
> > --
> > � (espen)
>
> I think you guys should cut Gavino some slack. He does troll in the
> sense that he posts on multiple forums (like a fisherman running
> multiple lines behind his boat in order to increase his chance of
> getting a bite). Gavino does not insult people however. He has never
> told me that my code "sucks" or that I "pulled it out of my ass" or
> that I am "diseased" --- all of which has been said to me by others
> (according to the self-appointed experts of c.l.f., every line of
> Forth I've ever written has sucked). Gavino is positive though, always
> asking if Forth could be used for some grandiose project (yes it
> could, but work would be required). It is still nonsense, but at least
> it is nice nonsense. I'm all for kill-listing trolls who tell
> programmers that their code sucks, without writing any code of their
> own --- but Gavino isn't one of these --- and neither is Mentifex, who
> I have also offered to help in regard to Forth programming.
>
> I have told Gavino in the past that he needs to start writing some
> code, and that I will help him as much as I can when he does. I told
> him the same thing again when he posted his IP-recognition question on
> comp.lang.forth:
> http://groups.google.com/group/comp.lang.forth/browse_thread/thread/bb39b0aa
> fa65a653# You guys could say as much in regard to Lisp.
>
> I've never written any non-trivial Lisp code myself, and yet I have
> posted messages on comp.lang.lisp on several occasions. I could be
> called a troll too! I don't consider myself a troll though, because I
> don't claim to be a leading expert on Lisp, and I don't insult people
> who do write Lisp code. I'll likely get going on the Lisp one of these
> days. It is difficult to build up any enthusiasm for programming
> though, when I know that the only result will be to have people tell
> me that my code sucks.
Those that infest c.l.l. are extremely vicious.
I have repeatedly proved that their code sucks by simply
posting superior code, although they will never admit it.
They are comletely devoid of honesty, fairness, and humanity.
As for coding ability, they are COBOL programmers at heart.
You cannot reason with them. Mutton is impervious to reason.
You cannot appeal to their better natures. They are rotten
to the core.
They are the worst enemies that Lisp ever had.
They and CommodeLisp deserve each other.
|
|
0
|
|
|
|
Reply
|
w_a_x_man (2778)
|
3/17/2011 8:24:36 PM
|
|
On 2011-03-17 16:24:36 -0400, WJ said:
> Those that infest c.l.l. are extremely vicious.
> They are comletely devoid of honesty, fairness, and humanity.
> As for coding ability, they are COBOL programmers at heart.
> You cannot reason with them.
> You cannot appeal to their better natures.
> They are rotten to the core.
> They are the worst enemies that Lisp ever had.
And yet you're still here.
Don't let the door hit you in the ass on the way out.
--
Raffael Cavallaro
|
|
0
|
|
|
|
Reply
|
raffaelcavallaro6342 (133)
|
3/17/2011 8:54:02 PM
|
|
On Mar 16, 10:10=A0am, namekuseijin <namekusei...@gmail.com> wrote:
> why not a generalized split function
> instead?
>
> for instance, I have this in my personal scheme lib:
>
Generalized is definitely better than specific. Thanks for posting
your code. I am going to have to learn Scheme to understand it. I
can't seem to find a good Scheme reference online.
I guess there are two situations that a split must handle:
1) just grab what is not a delimiter
2) reflect that data was not present between delimiters - as in input
records
Whitespace is always the first type, and non-whitespace could be the
first in the case of text, but is the second in the case of a
transaction file of records:
John,Watson,2221B Baker Street,,London,England
=3D> ("John" "Watson" "221B Baker Street" "" "London" "England")
or I suppose Common Lisp could do
=3D> ("John" "Watson" "221B Baker Street" nil "London" "England")
Then there is the further complication of a delimiter being data in
either case. The split() functions that come in the interpreted
languages never seem to handle the delimiter as data. Not sure if
there is any way for a regular expression based split to handle the
delimiter as data. Possibly if an escape sequence is used, but
typically double-quotes are used to enclose text where the delimiter
(normally a comma) is data: ,"221B Baker Street, Unit 10",
So it seems like there needs to be a split for each case, or a flag
for a single split.
|
|
0
|
|
|
|
Reply
|
zzbbaadd (349)
|
3/17/2011 9:14:32 PM
|
|
>
> Those that infest c.l.l. are extremely vicious.
> I have repeatedly proved that their code sucks by simply
> posting superior code, although they will never admit it.
I don't recall seeing you post Common Lisp code. Shouldn't your
"proofs" be in the code of the newsgroup. Can you prove that you are a
better piano player than someone else by playing the trumpet? If you
are trying to prove that a programming language is inferior why just
concentrate on Common Lisp. Why not post Ruby or Scheme code in the
tcl and Python newsgroups as well?
>
> They are comletely devoid of honesty, fairness, and humanity.
> As for coding ability, they are COBOL programmers at heart.
What are some things that COBOL programmers do that we should avoid?
>
> You cannot reason with them. =A0
> Mutton is impervious to reason.
> You cannot appeal to their better natures. =A0They are rotten
> to the core.
>
> They are the worst enemies that Lisp ever had.
> They and CommodeLisp deserve each other
|
|
0
|
|
|
|
Reply
|
zzbbaadd (349)
|
3/17/2011 10:17:55 PM
|
|
On Thu, 17 Mar 2011 15:17:55 -0700 (PDT), TheFlyingDutchman
<zzbbaadd@aol.com> wrote:
>What are some things that COBOL programmers do that we should avoid?
Well ... COBOL for one 8-)
|
|
0
|
|
|
|
Reply
|
George
|
3/18/2011 1:06:47 AM
|
|
TheFlyingDutchman <zzbbaadd@aol.com> wrote:
+---------------
| I can't seem to find a good Scheme reference online.
+---------------
http://community.schemewiki.org/?scheme-faq
http://schemers.org/Documents/Standards/
http://schemers.org/Tutorials/
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <http://rpw3.org/>
San Mateo, CA 94403
|
|
0
|
|
|
|
Reply
|
rpw3
|
3/18/2011 1:09:20 AM
|
|
On 2011-03-17 20:24:36 +0000, WJ said:
> They are comletely devoid of honesty, fairness, and humanity.
> As for coding ability, they are COBOL programmers at heart.
Obviously, then, being a rational person, you'd stop wasting your time
fighting them and go and do somethig more useful. I'd suggest fighting
the tide of FUD about Fukushima as a good starting point right now.
|
|
0
|
|
|
|
Reply
|
Tim
|
3/18/2011 9:58:45 AM
|
|
On Mar 16, 10:10=A0am, namekuseijin <namekusei...@gmail.com> wrote:
>
>why not a generalized split function instead?
>
> for instance, I have this in my personal scheme lib:
>
> (define (split txt . seps)
> =A0 ; aliases and convenient functions
> =A0 (let* ((ss (if (null? seps) #\space seps))
> =A0 =A0 =A0 =A0 =A0(sz (string-length txt))
> =A0 =A0 =A0 =A0 =A0(break? (if (pair? seps)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(lambda (i)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(pair? (memq (string-ref t=
xt (- i 1)) seps)))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(lambda (i)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(char=3D? ss (string-ref t=
xt (- i 1))))))
> =A0 =A0 =A0 =A0 =A0(result (lambda (i end r)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if (< i end) (cons (cons i end) r=
) r))))
> =A0 =A0 ; core functionality
> =A0 =A0 (let lp ((i sz) (end sz) (r '()))
> =A0 =A0 =A0 (cond ((=3D i 0) (result i end r))
> =A0 =A0 =A0 =A0 =A0 =A0 ((break? i) (lp (- i 1) (- i 1) (result i end r))=
)
> =A0 =A0 =A0 =A0 =A0 =A0 (#t (lp (- i 1) end r))))))
>
> ; testing:
> (split "foobar was here, just yesterday!")
> ; =3D> ((0 . 6) (7 . 10) (11 . 16) (17 . 21) (22 . 32))
>
> ; it gives indexes for substring, so:
> (let ((txt "foobar was here, just yesterday!"))
> =A0 (map (lambda (i) (substring txt (car i) (cdr i)))
> =A0 =A0 =A0 =A0(split txt #\space #\, #\!)))
> ; =3D> ("foobar" "was" "here" "just" "yesterday")
>
I am sure there is a better way to do this, but here is my version in
Guy'sRuby (Common Lisp):
(defun split (text &optional seps)
; convenience functions
(labels ( (result (i end the-list)
(if (< i end)
(cons (cons i end) the-list)
the-list)))
(let* ((separators (if (null seps) (list #\Space)
(if (characterp seps) (list seps) seps)))
(string_length (length text))
(i string_length)
(end string_length)
(the-list '()))
; core functionality
(loop
(cond ((=3D i 0)
(setq the-list (result i end the-list))
(return))
((member (char text (- i 1)) separators)
(setq the-list (result i end the-list))
(setq i (- i 1))
(setq end i))
(t (setq i (- i 1)))))
the-list)))
; testing:
(format t "~a~%" (split "foobar was here, just yesterday!"))
; =3D> ((0 . 6) (7 . 10) (11 . 16) (17 . 21) (22 . 32))
; it gives indexes for substring, so:
(format t "~a~%" (let ((txt "foobar was here, just yesterday!"))
(map 'list (lambda (a-cons) (subseq txt (car a-cons) (cdr a-cons)))
(split txt '(#\Space #\, #\!)))))
; =3D> ("foobar" "was" "here" "just" "yesterday")
|
|
0
|
|
|
|
Reply
|
TheFlyingDutchman
|
3/18/2011 11:26:14 PM
|
|
On Mar 17, 9:45=A0am, Raffael Cavallaro
<raffaelcavall...@pas.despam.s.il.vous.plait.mac.com> wrote:
> On 2011-03-17 07:52:01 -0400, Espen Vestre said:
>
> > I was hoping someone would appreciate my Wizard of Oz-reference
> > here...
>
> oh, we got the reference all right:
>
> If Gavino Had a Brain
> (to the tune of "If I Only Had a Brain")
>
> He could while away the hours,
> With lisp's numerical tower,
> Programming unchained
> No problems would he be posing
> Just parens neatly closing
> If Gavino had a brain
>
> He'd avoid a Usenet roasting
> By cutting out his posting
> Of questions asked in vain
> He'd no longer be a slacker
> He would be a true lisp hacker
> If Gavino had a brain
>
> Oh he, would surely be, an s-expression pro
> He would know where all the lambda list keywords go
> And he could write, a fine macro!
>
> He would not be merely trolling
> And setting our eyes rolling
> Another Usenet stain
> No more a newsgroup retard
> He would be a true lisp wizard
> If Gavino had a brain!
>
> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro
The point that I was making, is that somebody such as Gavino still has
the *potential* to start programming in Lisp or Forth or whatever. For
this reason, he should not be attacked.
By comparison, somebody who has claimed to be a leading expert, and
who has made a practice of belittling other people's code, can never
start programming. It is a little bit too late to come out with a
novice-level program that does some simple task such as parsing out an
IP address; that would be anti-climatic. Trolls such as this will
*never* post any code, but will tend to become increasingly
antagonistic over time as they struggle to bolster their ever-flimsy
leading-expert claim with bravado.
People who aren't already in this latter category shouldn't be
prodded, because once they start down this dark path they are unlikely
to turn back.
|
|
0
|
|
|
|
Reply
|
Hugh
|
3/19/2011 1:07:40 AM
|
|
On 2011-03-18 21:07:40 -0400, Hugh Aguilar said:
> The point that I was making, is that somebody such as Gavino still has
> the *potential* to start programming in Lisp or Forth or whatever.
Gavino has been posting things like "how in hell can I learn CLISP? PCL
seems lame" and "Were [sic] are all these great lisp apps if its such
great lang?" for about 5 years now. Google groups is your friend here
if you doubt it.
Having waited this long for him to realize his "potential" I think it's
fair to acknowledge that he is extraordinarily unlikely to become a
lisp programmer.
warmest regards
--
Raffael Cavallaro
|
|
0
|
|
|
|
Reply
|
Raffael
|
3/19/2011 3:08:52 AM
|
|
On Mar 18, 9:08=A0pm, Raffael Cavallaro
<raffaelcavall...@pas.despam.s.il.vous.plait.mac.com> wrote:
> On 2011-03-18 21:07:40 -0400, Hugh Aguilar said:
>
> > The point that I was making, is that somebody such as Gavino still has
> > the *potential* to start programming in Lisp or Forth or whatever.
>
> Gavino has been posting things like "how in hell can I learn CLISP? PCL
> seems lame" and "Were [sic] are all these great lisp apps if its such
> great lang?" for about 5 years now. Google groups is your friend here
> if you doubt it.
>
> Having waited this long for him to realize his "potential" I think it's
> fair to acknowledge that he is extraordinarily unlikely to become a
> lisp programmer.
>
> warmest regards
>
> --
> Raffael Cavallaro
I already knew about Gavino because he posts on comp.lang.forth too,
but I didn't know anything about you --- you have told me quite a lot
about yourself in this thread though --- is there anything else that I
need to know about you?
|
|
0
|
|
|
|
Reply
|
Hugh
|
3/19/2011 10:39:09 AM
|
|
On Mar 17, 9:24=A0pm, "WJ" <w_a_x_...@yahoo.com> wrote:
> Those that infest c.l.l. are extremely vicious.
> I have repeatedly proved that their code sucks by simply
> posting superior code, although they will never admit it.
So, you're basically saying that CL best practices are best practiced
practically, and not reading c.l.l. line noise?
Hmm... YES!! It's true!
Thanks for your insight.
P.S. It's clear to all of us that CL is far, far behind of (already)
all programming slangs.
We do it all for nostalgic reasons.
P.P.S. And now our all real problem: we all tried already, hundreds of
times, really, really hard, to choose a better one of language, but
choices are difficult!
P.P.P.S. In the end, we all ended up using the most intelligence/
practice-proven (decades wise) ever...
P.P.P.P.S. There's maybe a reason why the terms "intelligence" and
"wisdom" are spelled differently.
|
|
0
|
|
|
|
Reply
|
ok
|
3/19/2011 11:45:23 PM
|
|
ok <java.oke@gmail.com> writes:
> On Mar 17, 9:24�pm, "WJ" <w_a_x_...@yahoo.com> wrote:
>> Those that infest c.l.l. are extremely vicious.
>> I have repeatedly proved that their code sucks by simply
>> posting superior code, although they will never admit it.
>
> So, you're basically saying that CL best practices are best practiced
> practically, and not reading c.l.l. line noise?
>
> Hmm... YES!! It's true!
>
> Thanks for your insight.
>
> P.S. It's clear to all of us that CL is far, far behind of (already)
> all programming slangs.
> We do it all for nostalgic reasons.
IN UPPER CASE EVEN!
> P.P.S. And now our all real problem: we all tried already, hundreds of
> times, really, really hard, to choose a better one of language, but
> choices are difficult!
Scheme, Racket? http://www.informatimago.com/images/doctor-vs-racketeer.jpg
> P.P.P.S. In the end, we all ended up using the most intelligence/
> practice-proven (decades wise) ever...
>
> P.P.P.P.S. There's maybe a reason why the terms "intelligence" and
> "wisdom" are spelled differently.
--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.
|
|
0
|
|
|
|
Reply
|
Pascal
|
3/20/2011 7:45:19 AM
|
|
On Mar 17, 8:45=A0am, Raffael Cavallaro
<raffaelcavall...@pas.despam.s.il.vous.plait.mac.com> wrote:
> On 2011-03-17 07:52:01 -0400, Espen Vestre said:
>
> > I was hoping someone would appreciate my Wizard of Oz-reference
> > here...
>
> oh, we got the reference all right:
>
> If Gavino Had a Brain
> (to the tune of "If I Only Had a Brain")
>
> He could while away the hours,
> With lisp's numerical tower,
> Programming unchained
> No problems would he be posing
> Just parens neatly closing
> If Gavino had a brain
>
> He'd avoid a Usenet roasting
> By cutting out his posting
> Of questions asked in vain
> He'd no longer be a slacker
> He would be a true lisp hacker
> If Gavino had a brain
>
> Oh he, would surely be, an s-expression pro
> He would know where all the lambda list keywords go
> And he could write, a fine macro!
>
> He would not be merely trolling
> And setting our eyes rolling
> Another Usenet stain
> No more a newsgroup retard
> He would be a true lisp wizard
> If Gavino had a brain!
>
> warmest regards,
>
> Ralph
>
> --
> Raffael Cavallaro
lol u dork
|
|
0
|
|
|
|
Reply
|
gavino
|
3/20/2011 7:20:34 PM
|
|
This is more like the original Scheme code:
(defun split (txt &optional seps)
; aliases and convenience functions
(let* ((ss (if (null seps) #\Space seps))
(sz (length txt))
(break? (if (consp seps)
(lambda (i)
(member (char txt (- i 1)) seps))
(lambda (i)
(char= ss (char txt (- i 1)))))))
(labels ((result (i end r)
(if (< i end) (cons (cons i end) r) r))
; core functionality
(lp (i end r)
(cond ((= i 0)(result i end r))
((funcall break? i) (lp (- i 1) (- i 1) (result i
end r)))
(t (lp (- i 1) end r)))))
(lp sz sz (list) ))))
|
|
0
|
|
|
|
Reply
|
TheFlyingDutchman
|
3/23/2011 6:14:28 AM
|
|
|
41 Replies
25 Views
(page loaded in 0.474 seconds)
|