Re: a perl question

2011-01-06 Thread Matthew Seaman
On 05/01/2011 22:15, RW wrote:
 Personally I find that using cat makes things simpler and less error
 prone when reusing  pipelines in shell history.
 
 For example it's easier to edit 
 
  cat file | foo
 
 into 

  cat file | bar | foo
 or   cat file? | foo
 
 than editing 
 
  foo  file
 
 into
 
  bar  file | foo
 or   cat file? | foo

Little known factoid -- shell redirections can occur *anywhere* on the
command line.

%  foo cat
abcdefghijklmnopqrstuvwxyz
%  foo tr 'a-z' 'm-za-l'
mnopqrstuvwxyzabcdefghijkl

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
JID: matt...@infracaninophile.co.uk   Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature


Re: a perl question

2011-01-05 Thread Ian Smith
In freebsd-questions Digest, Vol 344, Issue 4, Message: 14
On Tue, 4 Jan 2011 23:24:01 -0700 Chad Perrin per...@apotheon.com wrote:
  On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr 
writes:
   
   Patrick cat asdf.txt | grep -v XYZ | grep -v bla
   
   And yet, you still have the Useless Use of Cat.
  
  The weirdest thing about most useless uses of cat is that not using cat
  would actually be a little clearer and involve fewer keystrokes -- as in
  this case.

Do you know of any 'less useless' or more economical way to do such as:

 % cat /boot/boot1 /boot/boot2 | diff - /boot/boot
 %

?, Ian
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-05 Thread Chip Camden
Quoth Chad Perrin on Tuesday, 04 January 2011:
 On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
   Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr 
   writes:
  
  Patrick cat asdf.txt | grep -v XYZ | grep -v bla
  
  And yet, you still have the Useless Use of Cat.
 
 The weirdest thing about most useless uses of cat is that not using cat
 would actually be a little clearer and involve fewer keystrokes -- as in
 this case.
 
 -- 
 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


I blame OOP.  Programmer thinks about the data stream before they think
about the process.  It's a nouns-first orientation.

-- 
Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com| http://chipsquips.com


pgpaYeod9JmjW.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread Chip Camden
Quoth Ian Smith on Thursday, 06 January 2011:
 In freebsd-questions Digest, Vol 344, Issue 4, Message: 14
 On Tue, 4 Jan 2011 23:24:01 -0700 Chad Perrin per...@apotheon.com wrote:
   On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
 Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr 
 writes:

Patrick cat asdf.txt | grep -v XYZ | grep -v bla

And yet, you still have the Useless Use of Cat.
   
   The weirdest thing about most useless uses of cat is that not using cat
   would actually be a little clearer and involve fewer keystrokes -- as in
   this case.
 
 Do you know of any 'less useless' or more economical way to do such as:
 
  % cat /boot/boot1 /boot/boot2 | diff - /boot/boot
  %
 
 ?, Ian
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

Here you're using cat for what it was intended -- conCATenation.  It's
the right tool for that job.

-- 
Sterling (Chip) Camden| sterl...@camdensoftware.com | 2048D/3A978E4F
http://camdensoftware.com | http://chipstips.com| http://chipsquips.com


pgp6YwaaNVSZJ.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread Chad Perrin
On Thu, Jan 06, 2011 at 12:07:13AM +1100, Ian Smith wrote:
 
 Do you know of any 'less useless' or more economical way to do such as:
 
  % cat /boot/boot1 /boot/boot2 | diff - /boot/boot
  %

Actually, that looks like a useful use of cat, whose original purpose it
is to concatenate the contents of two files.  `cat /boot/boot1
/boot/boot2` concatenates the contents of two files, so that the
resulting single text stream can be treated as a file to be compared by
diff to `/boot/boot`.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


pgpTrSURKXqIn.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread RW
On Wed, 5 Jan 2011 08:05:14 -0800
Chip Camden sterl...@camdensoftware.com wrote:

 Quoth Chad Perrin on Tuesday, 04 January 2011:

  The weirdest thing about most useless uses of cat is that not using
  cat would actually be a little clearer and involve fewer keystrokes
  -- as in this case.
  

 I blame OOP.  Programmer thinks about the data stream before they
 think about the process.  It's a nouns-first orientation.

You might easily get the same prejudice from data flow diagrams - or
plumbing. 

Personally I find that using cat makes things simpler and less error
prone when reusing  pipelines in shell history.

For example it's easier to edit 

 cat file | foo

into 
   
 cat file | bar | foo
or   cat file? | foo

than editing 

 foo  file

into

 bar  file | foo
or   cat file? | foo
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-05 Thread Chad Perrin
On Wed, Jan 05, 2011 at 10:15:38PM +, RW wrote:
 
 For example it's easier to edit 
 
  cat file | foo
 
 into 

  cat file | bar | foo
 or   cat file? | foo
 
 than editing 
 
  foo  file
 
 into
 
  bar  file | foo
 or   cat file? | foo

In this case, example was:

cat file | foo arg

. . . where it could have been:

foo arg file

That's just kind of absurd.  I mean, that sort of usage (foo arg file) is
exactly the purpose for which grep was designed.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


pgpuPZgJNS4Mz.pgp
Description: PGP signature


Re: a perl question

2011-01-05 Thread RW
On Wed, 5 Jan 2011 15:13:02 -0700
Chad Perrin per...@apotheon.com wrote:


 In this case, example was:
 
 cat file | foo arg
 
 . . . where it could have been:
 
 foo arg file
 
 That's just kind of absurd.  I mean, that sort of usage (foo arg
 file) is exactly the purpose for which grep was designed.
 
Obviously, I'm talking about the general case. If I'd meant grep I'd
have written grep and not foo.  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


a perl question

2011-01-04 Thread S Mathias
cat asdf.txt
bla-bla
bla-bla
bla[XYZ]
importantthing
another important thing
[/XYZ]
bla-bla
bla-bla
[XYZ]
yet another thing
hello!
[/XYZ]
bla-bla
etc.
$ SOMEPERLMAGIC asdf.txt  output.txt
$ cat output.txt
importantthing
another important thing
yet another thing
hello!


how can i sovle this question? what is SOMEPERLMAGIC? are there any perl gurus, 
that have a little spare time?

Thank you! :\


  
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Peter Vereshagin
You know St. Peter won't call my name, freebsd-questions!
2011/01/04 02:32:00 -0800 S Mathias smathias1...@yahoo.com = To 
freebsd-questions@freebsd.org :

$ perl -Mstrict -nwe 'print unless m/bla|XYZ/;'  asdf.txt

73! Peter pgp: A0E26627 (4A42 6841 2871 5EA7 52AB  12F8 0CE1 4AAC A0E2 6627)
--
http://vereshagin.org
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread krad
On 4 January 2011 10:32, S Mathias smathias1...@yahoo.com wrote:

 cat asdf.txt
 bla-bla
 bla-bla
 bla[XYZ]
 importantthing
 another important thing
 [/XYZ]
 bla-bla
 bla-bla
 [XYZ]
 yet another thing
 hello!
 [/XYZ]
 bla-bla
 etc.
 $ SOMEPERLMAGIC asdf.txt  output.txt
 $ cat output.txt
 importantthing
 another important thing
 yet another thing
 hello!


 how can i sovle this question? what is SOMEPERLMAGIC? are there any perl
 gurus, that have a little spare time?

 Thank you! :\



 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to 
 freebsd-questions-unsubscr...@freebsd.org



doesnt need to be perl either

cat asdf.txt | awk 'BEGIN {a=0} { if ( $0 ~ /\[XYZ\]/ ) a=1;  if ( $0 ~
/\[\/XYZ\]/ ) a=0; if ( a == 1) print $0}'

or something close to it
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Jonathan McKeown
On Tuesday 04 January 2011 12:32:00 S Mathias wrote:
 cat asdf.txt
 bla-bla
 bla-bla
 bla[XYZ]
 importantthing
 another important thing
 [/XYZ]
 bla-bla
 bla-bla
 [XYZ]
 yet another thing
 hello!
 [/XYZ]
 bla-bla
 etc.
 $ SOMEPERLMAGIC asdf.txt  output.txt
 $ cat output.txt
 importantthing
 another important thing
 yet another thing
 hello!

This could mean almost anything (witness another response which excludes lines 
containing blah or XYZ, which gives the desired output on your test input).

Are you actually trying to extract all the lines inside [XYZ]...[/XYZ] tags?

are the tags guaranteed not to occur on the lines you need to extract, as they 
appear here?

Because (all on one line)

perl -ne 'print if ($check = m{\[XYZ\]} .. m{\[/XYZ\]})  1 and 
$check !~ /E0$/' asdf.txt output.txt

produces the same output as you have above for the test input. (The .. range 
operator in scalar context is true as soon as the left-hand expression is 
true, and false as soon as the right-hand expression is true. It returns 1 
each time it becomes true, incrementing integers as it stays true, and 
appends E0 to the last number as it becomes false, which lets you exclude 
both endpoints).

Jonathan

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Patrick Bihan-Faou

Le 04/01/2011 14:06, krad a écrit :

On 4 January 2011 10:32, S Mathiassmathias1...@yahoo.com  wrote:


cat asdf.txt
bla-bla
bla-bla
bla[XYZ]
importantthing
another important thing
[/XYZ]
bla-bla
bla-bla
[XYZ]
yet another thing
hello!
[/XYZ]
bla-bla
etc.
$ SOMEPERLMAGIC asdf.txt  output.txt
$ cat output.txt
importantthing
another important thing
yet another thing
hello!


how can i sovle this question? what is SOMEPERLMAGIC? are there any perl
gurus, that have a little spare time?

Thank you! :\



___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
freebsd-questions-unsubscr...@freebsd.org



doesnt need to be perl either

cat asdf.txt | awk 'BEGIN {a=0} { if ( $0 ~ /\[XYZ\]/ ) a=1;  if ( $0 ~
/\[\/XYZ\]/ ) a=0; if ( a == 1) print $0}'

or something close to it


Simpler yet

cat asdf.txt | grep -v XYZ | grep -v bla

Patrick.
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Randal L. Schwartz
 Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr writes:

Patrick cat asdf.txt | grep -v XYZ | grep -v bla

And yet, you still have the Useless Use of Cat.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Devin Teske

On Jan 4, 2011, at 9:33 AM, Randal L. Schwartz wrote:

 Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr writes:
 
 Patrick cat asdf.txt | grep -v XYZ | grep -v bla
 
 And yet, you still have the Useless Use of Cat.

I know I'm joining the party late, but... what about:

grep -Ev '(XYZ|bla)' asdf.txt

or

awk '!/XYZ/  !/bla/ {print}' asdf.txt

ok... end useless contribution.

 
 -- 
 Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
 Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
 See http://methodsandmessages.posterous.com/ for Smalltalk discussion
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org

--
Cheers,
Devin Teske

- CONTACT INFORMATION -
Business Solutions Consultant II
FIS - fisglobal.com
510-735-5650 Mobile
510-621-2038 Office
510-621-2020 Office Fax
909-477-4578 Home/Fax
devin.te...@fisglobal.com

- LEGAL DISCLAIMER -
This message  contains confidential  and proprietary  information
of the sender,  and is intended only for the person(s) to whom it
is addressed. Any use, distribution, copying or disclosure by any
other person  is strictly prohibited.  If you have  received this
message in error,  please notify  the e-mail sender  immediately,
and delete the original message without making a copy.

- FUN STUFF -
-BEGIN GEEK CODE BLOCK-
Version 3.1
GAT/CS d(+) s: a- C++() UB$ P++() L++() !E--- W++ N? o? K- w O
M+ V- PS+ PE Y+ PGP- t(+) 5? X+(++) R++ tv(+) b+(++) DI+(++) D(+) G+++ e+ h
r++ y+ 
--END GEEK CODE BLOCK--
http://www.geekcode.com/

- END TRANSMISSION -

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread RW
On Tue, 4 Jan 2011 10:01:47 -0800
Devin Teske dte...@vicor.com wrote:

 
 On Jan 4, 2011, at 9:33 AM, Randal L. Schwartz wrote:
 
  Patrick == Patrick Bihan-Faou
  patrick.bihan-f...@teambox.fr writes:
  
  Patrick cat asdf.txt | grep -v XYZ | grep -v bla
  
  And yet, you still have the Useless Use of Cat.
 
 I know I'm joining the party late, but... what about:
 
 grep -Ev '(XYZ|bla)' asdf.txt
 
 or
 
 awk '!/XYZ/  !/bla/ {print}' asdf.txt
 
 ok... end useless contribution.

It's odd that people seem to be taking bla-bla so literally, when it's
clearly a place holder for arbitary text. 
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Devin Teske
On Tue, 2011-01-04 at 22:12 +, RW wrote:
 On Tue, 4 Jan 2011 10:01:47 -0800
 Devin Teske dte...@vicor.com wrote:
 
  
  On Jan 4, 2011, at 9:33 AM, Randal L. Schwartz wrote:
  
   Patrick == Patrick Bihan-Faou
   patrick.bihan-f...@teambox.fr writes:
   
   Patrick cat asdf.txt | grep -v XYZ | grep -v bla
   
   And yet, you still have the Useless Use of Cat.
  
  I know I'm joining the party late, but... what about:
  
  grep -Ev '(XYZ|bla)' asdf.txt
  
  or
  
  awk '!/XYZ/  !/bla/ {print}' asdf.txt
  
  ok... end useless contribution.
 
 It's odd that people seem to be taking bla-bla so literally, when it's
 clearly a place holder for arbitary text. 

Maybe because the OP should have said:

How do I get the text between [XYZ] and [/XYZ]

A demarcing field-search is different than a pruning line-search.

This is what the OP was looking for:

awk -v tag=XYZ '
BEGIN { buf =  }
$0 ~ \\[tag\\], $0 ~ \\[/tag\\] \
{
if ( match($0, \\[/tag\\]) ) \
{
buf = buf substr($0, 0, RSTART - 1)
sub(.*\\[tag\\], , buf)
sub(/^\n*/, , buf)
sub(/\n*$/, , buf)
print buf
buf = 
next
} else
buf = buf $0\n
}
END { if ( length(buf) ) print buf }' asdf.txt

or, if you would prefer to have it all on one line:

awk -v tag=XYZ 'BEGIN { buf =  } $0 ~ \\[tag\\], $0 ~ \\[/tag\
\] { if ( match($0, \\[/tag\\]) ) { buf = buf substr($0, 0, RSTART
- 1); sub(.*\\[tag\\], , buf); sub(/^\n*/, , buf); sub(/\n*$/,
, buf); print buf; buf = ; next } else buf = buf $0\n } END { if
( length(buf) ) print buf }' asdf.txt

or, if you would like it as an alias:

for bash...

alias between_xyz='awk -v tag=XYZ '\''BEGIN { buf =  } $0 ~ \\[tag\
\], $0 ~ \\[/tag\\] { if ( match($0, \\[/tag\\]) ) { buf = buf
substr($0, 0, RSTART - 1); sub(.*\\[tag\\], , buf); sub(/^\n*/,
, buf); sub(/\n*$/, , buf); print buf; buf = ; next } else buf =
buf $0\n } END { if ( length(buf) ) print buf }'\'

for csh:

alias between_xyz 'awk -v tag=XYZ '\''BEGIN { buf =  } $0 ~ \\[tag\
\], $0 ~ \\[/tag\\] { if ( match($0, \\[/tag\\]) ) { buf = buf
substr($0, 0, RSTART - 1); sub(.*\\[tag\\], , buf); sub(/^\n*/,
, buf); sub(/\n*$/, , buf); print buf; buf = ; next } else buf =
buf $0\n } END { if ( length(buf) ) print buf }'\'

Usage:

between_xyz asdf.txt

Of course, this can even be improved upon further...

As a shell function:

# between $what $file [$file ...]
#
# Split out lines between [$what] and [/$what] using awk(1).
#
between()
{
awk -v tag=$1 '
BEGIN { buf =  }
$0 ~ \\[tag\\], $0 ~ \\[/tag\\] \
{
if ( match($0, \\[/tag\\]) ) \
{
buf = buf substr($0, 0, RSTART - 1)
sub(.*\\[tag\\], , buf)
sub(/^\n*/, , buf)
sub(/\n*$/, , buf)
print buf
buf = 
next
} else
buf = buf $0\n
}
END { if ( length(buf) ) print buf }
' $@
}

Or, for those csh users, how about a fancy alias?:

alias between 'awk -v tag=\!^ '\''BEGIN { buf =  } $0 ~ \\[tag\
\], $0 ~ \\[/tag\\] { if ( match($0, \\[/tag\\]) ) { buf = buf
substr($0, 0, RSTART - 1); sub(.*\\[tag\\], , buf); sub(/^\n*/,
, buf); sub(/\n*$/, , buf); print buf; buf = ; next } else buf =
buf $0\n } END { if ( length(buf) ) print buf }'\'' \!:2-$'

Usage:

between XYZ asdf.txt

AND... (lol)... last but not least...

If you want to have case-insensitivity, you'll have to change:

BEGIN { buf =  }

to:

BEGIN { IGNORECASE = 1; buf =  }


NOTE: FYI, when you need to grab text that spans multiple lines between
two field delimiters, C/C++ is superior to perl/awk which excel at line-
based I/O versus block I/O. However, I conclude that the OP wanted
something that was executable from the command-line (considering that
he/she actually gave a basic construct for a perl one-liner (which might
as well be an awk one-liner considering FreeBSD doesn't come with Perl
in the base anymore and thus not every machine is guaranteed to have
perl -- while every machine has awk).

ANOTHER NOTE: The above is not intended to start a language flame-war...
just an observation. If you have observed an easy _and_ convenient
method that _does_ use perl/awk (in a manner more efficient than the
above), I'm sure the OP/list would love it. Otherwise, I really do view
this operation as being easier in C using functions like strchr,
strrchr, etc.
-- 
Cheers,
Devin Teske

- CONTACT INFORMATION -
Business Solutions Consultant II
FIS - fisglobal.com
510-735-5650 Mobile
510-621-2038 Office
510-621-2020 Office Fax
909-477-4578 Home/Fax
devin.te...@fisglobal.com

- LEGAL DISCLAIMER -
This message  

Re: a perl question

2011-01-04 Thread Randal L. Schwartz
 RW == RW  rwmailli...@googlemail.com writes:

RW It's odd that people seem to be taking bla-bla so literally, when it's
RW clearly a place holder for arbitary text. 

That's the problem when you provide an example instead of a rule.  But
oddly enough, once you figure out the actual rule, translating that into
a program is generally rather mechanical.  Hence the irony of such
questions.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: a perl question

2011-01-04 Thread Chad Perrin
On Tue, Jan 04, 2011 at 09:33:03AM -0800, Randal L. Schwartz wrote:
  Patrick == Patrick Bihan-Faou patrick.bihan-f...@teambox.fr writes:
 
 Patrick cat asdf.txt | grep -v XYZ | grep -v bla
 
 And yet, you still have the Useless Use of Cat.

The weirdest thing about most useless uses of cat is that not using cat
would actually be a little clearer and involve fewer keystrokes -- as in
this case.

-- 
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]


pgpaBZTKvL8ix.pgp
Description: PGP signature


tricky perl question - ascending order

2010-05-23 Thread Jozsi Vadkan
or maybe in bash..
script/one liner e.g.: input: http://pastebin.com/raw.php?i=pMZPEsMZ

i want to make this output from it:
http://pastebin.com/raw.php?i=kH8VxT0A


So from the input, i want to make an ascendant order, how many things
are under a SOMETHING-XX

Does anyone has any perl magic in the pocket, how to do this? :D

Thank you very, very much..:\

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: tricky perl question - ascending order

2010-05-23 Thread Randal L. Schwartz
 Jozsi == Jozsi Vadkan jozsi.avad...@gmail.com writes:

Jozsi So from the input, i want to make an ascendant order, how many things
Jozsi are under a SOMETHING-XX

So you just want paragraphs ordered by line count?

Something like this, untested:

perl -00 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_, tr/\n//], 
' input output

Keywords: Schwartzian Transform, paragraph mode.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
mer...@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: tricky perl question - ascending order

2010-05-23 Thread Jozsi Vadkan
The solution [i asked Randal L. Schwartz, because i didn't worked, and
he said he just forgot the -e, now it works!!]:

perl -00 -e 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_,
tr/\n//], '  before.txt  after.txt

Thank you!!


  Jozsi == Jozsi Vadkan jozsi.avad...@gmail.com writes:
 
 Jozsi So from the input, i want to make an ascendant order, how many things
 Jozsi are under a SOMETHING-XX
 
 So you just want paragraphs ordered by line count?
 
 Something like this, untested:
 
 perl -00 'print map $_-[0], sort { $a-[1] = $b-[1] } map [$_, tr/\n//], 
 ' input output
 
 Keywords: Schwartzian Transform, paragraph mode.
 

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Re: Perl question.

2006-08-17 Thread Dan Nelson
In the last episode (Aug 17), Greg Groth said:
 I'm trying to install bandersnatch in conjunction with Jabber2 and
 running into some trouble.  I'm following the how-to at:
 http://www.funkypenguin.co.za/bandersnatch_with_jabberd2
 
 I've installed all of the listed sources from the ports, but when I
 run bandersnatch2.pl, I receive the following error:
 
 Can't locate POE/Preprocessor.pm in @INC
 
 It seems that Preprocessor.pm does not exist on my system.  Can
 someone tell me which relevant port would have this module? 
 Installing POE::Preprocessor from CPAN comes up with a blank, as well
 as searching the ports for anything with the same name.

A quick web search shows that POE::Preprocessor was removed from POE in
March.  http://search.cpan.org/src/RCAPUTO/POE-0.3601/CHANGES :

 2006-03-11 23:11:39 (r1887) by rcaputo
  poe/lib/POE/Preprocessor.pm D; poe/lib/POE/Macro D;
  poe/tests/10_units/01_preprocessor D; poe/mylib/preprocessor.perl A;
  poe/mylib/PoeBuildInfo.pm M

Remove POE::Preprocessor. Replaced it with a simple, almost one-liner
preprocessor that's run at Makefile.PL time. 

-- 
Dan Nelson
[EMAIL PROTECTED]
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Perl question.

2006-08-17 Thread Greg Groth



Dan Nelson wrote:


A quick web search shows that POE::Preprocessor was removed from POE in
March.  http://search.cpan.org/src/RCAPUTO/POE-0.3601/CHANGES :

 2006-03-11 23:11:39 (r1887) by rcaputo
  poe/lib/POE/Preprocessor.pm D; poe/lib/POE/Macro D;
  poe/tests/10_units/01_preprocessor D; poe/mylib/preprocessor.perl A;
  poe/mylib/PoeBuildInfo.pm M

Remove POE::Preprocessor. Replaced it with a simple, almost one-liner
preprocessor that's run at Makefile.PL time. 



Thanks for finding this for me.  A search on http://search.cpan.org for 
POE::Preprocessor brought up zilch, not sure why it couldn't locate this 
doc.


Best regards,
Greg Groth
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: perl question

2004-08-14 Thread jason
Bart Silverstrim wrote:
On Aug 13, 2004, at 1:10 AM, AlanSung wrote:
IMHO, bsdpan-* means install via cpan directory (not via ports),
p5-* means installed from ports..

Okay.  Nuts.  That's what I was afraid of.
I guess I was a little thrown because the bsdpan modules are showing 
up with portversion and portupgrade, which I had always associated 
with just the ports database and ports collection.

And yes, if you can find expected module in ports tree, it is better
install from ports than install from cpan driectly..

Okay...question...
When I set up this server, it was (at the time) just for the purpose 
of this portal server (web based).  I followed their directions for 
Linux and FreeBSD, and did it to the letter, etc...a lot of install 
this and this from CPAN using this command line instruction... etc. etc.

In this case, R'ing the F'ing M was apparently a bad idea :-(  Wish 
this server software were available as a port!

Anyway, I am tentatively hoping to replace the bsdpan modules with 
ports' p5 modules.  Is there a method AND ORDER to best attempt this, 
so the application (hopefully) won't break?  I don't want to install a 
p5 port and remove a bsdpan module only to have the bsdpan module 
erase parts of the p5 modules in the process :-(

-Bart
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
[EMAIL PROTECTED]

I just noticed you have 2 threads on this.  Are they the same?
I think it was a case of R'ing the Wrong F'ing M.  My other post has 
some info.  Follow the docs you used to install the stuff to remove it.  
When you have your system back to a new clean enviroment use the ports 
to add what you want.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: perl question

2004-08-13 Thread Bart Silverstrim
On Aug 13, 2004, at 1:10 AM, AlanSung wrote:
IMHO, bsdpan-* means install via cpan directory (not via ports),
p5-* means installed from ports..
Okay.  Nuts.  That's what I was afraid of.
I guess I was a little thrown because the bsdpan modules are showing up 
with portversion and portupgrade, which I had always associated with 
just the ports database and ports collection.

And yes, if you can find expected module in ports tree, it is better
install from ports than install from cpan driectly..
Okay...question...
When I set up this server, it was (at the time) just for the purpose of 
this portal server (web based).  I followed their directions for Linux 
and FreeBSD, and did it to the letter, etc...a lot of install this and 
this from CPAN using this command line instruction... etc. etc.

In this case, R'ing the F'ing M was apparently a bad idea :-(  Wish 
this server software were available as a port!

Anyway, I am tentatively hoping to replace the bsdpan modules with 
ports' p5 modules.  Is there a method AND ORDER to best attempt this, 
so the application (hopefully) won't break?  I don't want to install a 
p5 port and remove a bsdpan module only to have the bsdpan module erase 
parts of the p5 modules in the process :-(

-Bart
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: perl question

2004-08-12 Thread jason
Bart Silverstrim wrote:
What is the difference between bsdpan and the p5 modules in the ports 
collection?

-Bart
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to 
[EMAIL PROTECTED]

The ports version has been ported to freebsd.  It works without 
problems(ideally ofcourse).  Always use ports if you can and there 
should be no problems installing software like you might find on linux.  
To see the differences go to /usr/ports/lang/per_or_whatever and you can 
read everything in there.  The files folder contains the actual patches 
and changes to the original source to make it work without problems.
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: perl question

2004-08-12 Thread AlanSung
IMHO, bsdpan-* means install via cpan directory (not via ports),
p5-* means installed from ports..

And yes, if you can find expected module in ports tree, it is better
install from ports than install from cpan driectly..

Sometimes we need customized configuration args...

On Thu, 12 Aug 2004 22:09:23 -0400, Bart Silverstrim
[EMAIL PROTECTED] wrote:
 What is the difference between bsdpan and the p5 modules in the ports
 collection?
 
 -Bart
 
 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]
 


-- 
COBRA Lab in NTU EE
IAS Lab in SINICA IIS
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: perl question

2004-01-28 Thread Namik Dala
On Wed, Jan 28, 2004 at 08:55:48PM -0500, Roger Williams wrote:
 $realname =~ tr# a-zA-Z0-9\-,./'\200-377##dc;
   ^
There is a backslash missing.

-Namik-
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


OT: Another perl question

2004-01-18 Thread Gary Kline

Is there an easy way of determining file - determine file type
in perl? at least as certain as magic(5) can ascertain?

E.g:

if (($ftype = file ($ARV[i])) eq script){
## do abc;
}
else if ($ftype eq Mail){
## do def;
}
else if ($type eq C program){
## do xyz;
}
.
.
.

I've been poking around perl tutorial sites; so far, nada.
Thought I'd ask the wizards.

thanks for any clues,

gary


-- 
   Gary Kline [EMAIL PROTECTED]   www.thought.org Public service Unix

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: OT: Another perl question

2004-01-18 Thread Chris Pressey
On Sun, 18 Jan 2004 15:55:42 -0800
Gary Kline [EMAIL PROTECTED] wrote:

   
   Is there an easy way of determining file - determine file type
   in perl? at least as certain as magic(5) can ascertain?
 
   E.g:
 
   if (($ftype = file ($ARV[i])) eq script){
   ## do abc;
   }
   else if ($ftype eq Mail){
   ## do def;
   }
   else if ($type eq C program){
   ## do xyz;
   }
   .
   .
   .
 
   I've been poking around perl tutorial sites; so far, nada.
   Thought I'd ask the wizards.
 
   thanks for any clues,
 
   gary

How about /usr/ports/devel/p5-File-MMagic ?

This module is to guess file type from its contents like file(1)
command.

-Chris
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


OT - Perl Question

2003-11-11 Thread Darryl Hoar
I am trying to learn perl.  I am going through a tutorial and have come
across a syntax error I can't figure out.

Here's the code:

print Please tell me your name: ;
chop ($name=STDIN);

print Please tell me your nationality: ;
chop ($nation=STDIN);

if ( $nation eq British  or  $nation eq New Zealand )
{
 print Hallo $name, pleased to meet you!\n;

}

when I try to run it, it generates a compile errors on the
if line.

I know its the conditional test, but don't know how to fix
it to be syntactically correct in perl.

Any help?

thanks,
-D
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: OT - Perl Question

2003-11-11 Thread Fernando Gleiser
On Tue, 11 Nov 2003, Darryl Hoar wrote:


 if ( $nation eq British  or  $nation eq New Zealand )
 {
  print Hallo $name, pleased to meet you!\n;

 }

 when I try to run it, it generates a compile errors on the
 if line.

 I know its the conditional test, but don't know how to fix
 it to be syntactically correct in perl.

Precedence errors, change it to:

if ( ($nation eq British)  ||  ($nation eq New Zealand) )

When in doubt, parentesize defensivelly :)

Hope this helps.


Fer


 Any help?

 thanks,
 -D
 ___
 [EMAIL PROTECTED] mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]


___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: OT - Perl Question

2003-11-11 Thread Matthew Seaman
On Tue, Nov 11, 2003 at 02:57:04PM -0600, Darryl Hoar wrote:
 I am trying to learn perl.  I am going through a tutorial and have come
 across a syntax error I can't figure out.
 
 Here's the code:
 
 print Please tell me your name: ;
 chop ($name=STDIN);
 
 print Please tell me your nationality: ;
 chop ($nation=STDIN);
 
 if ( $nation eq British  or  $nation eq New Zealand )
 {
  print Hallo $name, pleased to meet you!\n;
 
 }
 
 when I try to run it, it generates a compile errors on the
 if line.
 
 I know its the conditional test, but don't know how to fix
 it to be syntactically correct in perl.
 
 Any help?

Works fine if you ask me:

happy-idiot-talk:/tmp:% cat  foo.pl
#!/usr/bin/perl -w

print Please tell me your name: ;
chop ($name=STDIN);

print Please tell me your nationality: ;
chop ($nation=STDIN);

if ( $nation eq British  or  $nation eq New Zealand )
{
 print Hallo $name, pleased to meet you!\n;

}

happy-idiot-talk:/tmp:% perl -cw foo.pl 
foo.pl syntax OK
happy-idiot-talk:/tmp:% chmod +x foo.pl 
happy-idiot-talk:/tmp:% ./foo.pl 
Please tell me your name: Matthew
Please tell me your nationality: British
Hallo Matthew, pleased to meet you!

There was probably a typo in your original script which you've managed
to inadvertently fix when you copied your code into the e-mail.

Cheers,

Matthew


-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK


pgp0.pgp
Description: PGP signature


Re: perl question about @INC

2003-01-19 Thread Joe Marcus Clarke
On Sun, 2003-01-19 at 23:32, David Banning wrote:
 I got the error running a perl script;
 
 Can't locate Getopt/Simple.pm in @INC (@INC contains: 
/usr/local/lib/perl5/site_perl/5.005/i386-freebsd 
/usr/local/lib/perl5/site_perl/5.005 . /usr/libdata/perl/5.00503/mach 
/usr/libdata/perl/5.00503) at ./adddir.pl line 28.
 BEGIN failed--compilation aborted at ./adddir.pl line 28.
 
 su-2.03# locate Simple.pm
 /usr/local/lib/perl5/site_perl/5.005/LWP/Simple.pm
  
 Where is the @INC alluded to in the error message and how would
 I go about adding the real location of the file it is seeking?

Usually scripts use Getopt::Std or Getopt::Long for command line option
parsing.  However, there is a third party Getopt::Simple:

http://search.cpan.org/author/RSAVAGE/Getopt-Simple-1.45/Simple.pm

There doesn't appear to be a port of this module to FreeBSD, however. 
You'd have to download and build the module.

Joe

 
 To Unsubscribe: send mail to [EMAIL PROTECTED]
 with unsubscribe freebsd-questions in the body of the message
-- 
PGP Key : http://www.marcuscom.com/pgp.asc



signature.asc
Description: This is a digitally signed message part


RE: Perl question... calculating difference in time..

2002-12-05 Thread Jeff MacDonald
look into the perl module Date::Calc,
it's has ALOT of features that are quite useful for date manipulation.

jeff.

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED]]On Behalf Of Eric Six
 Sent: Thursday, December 05, 2002 1:44 PM
 To: '[EMAIL PROTECTED]'
 Subject: Perl question... calculating difference in time..
 
 
 I know this isn't a perl list, but this is a perl on freebsd question! ;)
 
 I have a script that is sorting log files. I want to calculate the total
 time between log entrys. Here is the format of the log files:
 
 Dec 05 09:51:48.452 info info.info data
 ...
 Dec 05 09:53:49.543 info info.info data
 
 The output should return something along the lines of: total time between
 log entries 02:01:01.091.
 
 I have the time fields pulled out but I cannot figure out how to seprate
 them into a calculatable format. And if this was run from after 
 midnight and
 the log files rolled back to 23:00, how to calculate this..Any 
 help is much
 appreciated!
 
 TIA
 Eric
 
 To Unsubscribe: send mail to [EMAIL PROTECTED]
 with unsubscribe freebsd-questions in the body of the message
 

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message



Re: Perl question... calculating difference in time..

2002-12-05 Thread Matthew Seaman
On Thu, Dec 05, 2002 at 02:00:20PM -0500, Jeff MacDonald wrote:
 look into the perl module Date::Calc,
 it's has ALOT of features that are quite useful for date manipulation.

The Time::ParseDate module by David Muir Sharnoff looks just the
ticket.

http://search.cpan.org/author/MUIR/Time-modules-2002.1001/lib/Time/ParseDate.pm

It essentially does the reverse of strftime(3) --- and once you've got
the time expressed as seconds since the epoch, the rest of the
calculations required should be easy.

It's available in ports as part of devel/p5-Time.

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   26 The Paddocks
  Savill Way
  Marlow
Tel: +44 1628 476614  Bucks., SL7 1TH UK

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-questions in the body of the message