Re: shell, perl script to count identical lines?

2009-08-17 Thread Warren Michelsen

At 10:28 AM -0500 8/17/09, Fritz Anderson sent email regarding Re: 
shell, perl script to count identical lines?:
>On 17 Aug 2009, at 10:19 AM, Warren Michelsen wrote:
>
>>  Does anyone have a shell or Perl script for BBEdit which will count 
>>  identical lines in the front-most document and report the results?
>
>man uniq

Aha!

#!/bin/sh
uniq -c "$1"

does the trick. Man, I love Unix. (and BBEdit.)




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: shell, perl script to count identical lines?

2009-08-17 Thread Rich Siegel

On 8/17/09 at 11:19 AM, wmichel...@gmail.com (Warren Michelsen) wrote:

>Does anyone have a shell or Perl script for BBEdit which will count
>identical lines in the front-most document and report the results?
>
>Ideally, create a new text document with a listing of each unique line
>and the number of instances of that line, perhaps preceding that line
>so the results can be sorted by number of occurrences.

Does it have to be a Perl script? That sounds a lot like what 
"Process Duplicate Lines" does...

R.
-- 
Rich Siegel Bare Bones Software, Inc.
  

Someday I'll look back on all this and laugh... until they 
sedate me.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: shell, perl script to count identical lines?

2009-08-17 Thread Fritz Anderson

On 17 Aug 2009, at 10:19 AM, Warren Michelsen wrote:

> Does anyone have a shell or Perl script for BBEdit which will count  
> identical lines in the front-most document and report the results?

man uniq

— F


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



shell, perl script to count identical lines?

2009-08-17 Thread Warren Michelsen

Does anyone have a shell or Perl script for BBEdit which will count identical 
lines in the front-most document and report the results?

Ideally, create a new text document with a listing of each unique line and the 
number of instances of that line, perhaps preceding that line so the results 
can be sorted by number of occurrences.

I've distilled my DNS server query log down to just the domain looked up and 
the type query (eliminating date, time, querying IP, etc.). Now I'd like to get 
a count of the lookups to see which are looked up most often.

I have a 'Count Identical Lines' AppleScript but with 1,112,000+ lines to be 
counted, I don't even want to attempt it.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Auto-Close elements

2009-08-17 Thread Maarten Sneep

On Sat, 15 Aug 2009 18:03:02 -0700 (PDT), Moop 
wrote:
> Is there a way to get BBEdit to auto-close elements? Like if I'm
> writing an XML/HTML document, and type  it should automatically
> insert  for me. I know that I can do something like this when
> writing HTML, but custom XML doesn't have this feature.

Almost automatically: you can assign a command-key equivalent to the
'close current tag' command in the HTML tools menu (see page 253 in the
user manual). This works well for me, not only in html but also in other
xml dialects (tested with gpx). Tag maker will probably not work (it would
be nice if the doctype was followed, and the list for the tag maker adapts
to the current document type, but one can only dream).

Maarten



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: sftp as root

2009-08-17 Thread Warren Michelsen

At 3:56 PM +1000 8/17/09, Charlie Garrison sent email regarding Re: 
sftp as root:
>Good afternoon,
>
>On 16/08/09 at 9:24 AM -0700, Warren Michelsen
> wrote:
>
>>Charlie, are you saying you were able to sftp as root with no
>  >password and it worked?
>...
>I can connect via sftp using BBEdit with the root account. It
>works fine for me.

With no password?

>
>If you can ssh to the machine as root, then you should be able
>to connect as root from with BBEdit.

That was my expectation.

>
>>So I'd be very curious to know if anyone can successfully
>>connect via BBE's sftp as root with no password.
>
>I can, so that's at least one. I throw a question back; are you
>able to connect as root (without password) via ssh from the
>command line?

Yes.

Previously I would ssh to the server in question (in Terminal) as 
other than root then su to root (or sudo) to edit configuration and 
other files that I could not edit without being root. But I would 
like the convenience of BBEdit's features when editing such files. 
Since sftp cannot 'su' to root, I enabled the root account and set 
it, as I did my other account, to use keys for password-less log-in.

ssh from Terminal works just fine. I'd expected that just leaving out 
the password when sftp'ing as root would Just Work but it doesn't, 
and I'm puzzled.

I can use passwordl-ess sftp using another non-root account. Root 
seems to be treated differently.

I was watching both secure.log and system.log while trying to get BBE 
to log in as root without a password over a network connection.

Here's what secure.log showed:

Aug 14 11:08:22 smtp com.apple.SecurityServer: authinternal failed to 
authenticate user root.
Aug 14 11:08:22 smtp com.apple.SecurityServer: Failed to authorize 
right system.login.tty by process /usr/sbin/sshd for authorization 
created by /usr/sbin/sshd.
Aug 14 11:08:22 smtp com.apple.SecurityServer: authinternal failed to 
authenticate user root.
Aug 14 11:08:22 smtp com.apple.SecurityServer: Failed to authorize 
right system.login.tty by process /usr/sbin/sshd for authorization 
created by /usr/sbin/sshd.
Aug 14 11:08:22 smtp com.apple.SecurityServer: authinternal failed to 
authenticate user root.
Aug 14 11:08:22 smtp com.apple.SecurityServer: Failed to authorize 
right system.login.tty by process /usr/sbin/sshd for authorization 
created by /usr/sbin/sshd.

here's what system.log showed:

Aug 14 11:08:22 smtp DirectoryService[160]: Failed Authentication 
return is being delayed due to over five recent auth failures for 
username: root.
Aug 14 11:08:22 smtp sshd[19730]: error: PAM: Authentication failure 
for root from [my.ip]
Aug 14 11:08:22 smtp sshd[19730]: error: PAM: Authentication failure 
for root from [my.ip]
Aug 14 11:08:22 smtp sshd[19730]: error: PAM: Authentication failure 
for root from [my.ip]


So, I suspect that hacker/attackers are attempting to log in as root 
and running up this counter which has a limit of 5.

What is curious is, of course, that I can ssh as root successfully 
via Terminal and the 5-limit does not affect me.

Do normal ssh and ssh tunnels use different authentication? Does 
normal ssh not use PAM?

Any suggestions as to what I should watch/monitor while attempting 
BBE's sftp as root would be appreciated.







--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: GREP replace pattern and File Creation from List Question

2009-08-17 Thread Ronald J Kimball

On Mon, Aug 17, 2009 at 04:24:43AM -0700, xbsjason wrote:
> 
> Hey guys, I hate to reply to my own post for fear of spamming but I
> was hoping someone had the time to take a look at my initial questions
> above, as I'm still at a standstill. 8(
> 
> On Aug 7, 12:11?pm, xbsjason  wrote:
> > Hello all,
> >
> > My question is two-fold. I finally figured out agrepsearch and
> > replacepatternthat suits my needs. Its a really simple one, but a
> > huge step forward for me.
> >
> > SEARCHGREP
> > ^([^\t]+)\t([^\t]+)$
> >
> > REPLACE WITH
> > \2.\rNote: \1\r
> >
> > So my question is this... Is it possible to create a replacepattern
> > that will change the case for \2 to Capitalized case, but only if the
> > included words are 4 or more letters? As an example I have this:
> >
> > Model1495 \t Base cabinet, hardware, and related accessories
> >
> > Which, when run through mygrepsearch and replace becomes this:
> >
> > Base cabinet, hardware, and related accessories.
> > Note: Model1495
> >
> > But I'd like it to become this (note the capitalized case for words 
> > inpattern2 longer than 4 characters):
> >
> > Base Cabinet, Hardware, and Related Accessories.
> > Note: Model1495
> >
> > Is this possible?

It is not possible to do this with just a simple Grep search.  You could do
this with a filter, however.  Here's one written in Perl:

#!perl -pl

s{^([^\t]+)\t([^\t]+)$}
 { my($note, $title) = ($1, $2); $title =~ s/(\S{4,})/\u$1/g;
   "$title.\nNote: $note" }ge;

__END__


Although since we're in Perl, instead of nested substitutions we could just
use split:

#!perl -nl

my ($note, $title) = split /\t/;
$title =~ s/(\S{4,})/\u$1/g;
print "$title.\nNote: $note";

__END__


> > Next question, if I have a list of item names, can I quickly create a
> > text file for each of them?
> >
> > Say my list is simple each item on a new line like so...
> >
> > Item 1
> > Item 2
> > Item 3
> >
> > and I want Item1.txt, Item2.txt, Item3.txt
> >
> > Thanks for the time.

I don't know if there's a built-in feature in BBEdit to do this.  Here's
a very simple Perl script:

#!perl -nl

s/\s+//g;
open (my $fh, '>>', "$_.txt")
  or die "Can't open $_.txt: $!\n";

This opens each file in append mode, so it won't overwrite any files that
already exist.  Although it removes whitespace, it does not verify that the
filename is actually valid.

HTH,
Ronald

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: GREP replace pattern and File Creation from List Question

2009-08-17 Thread xbsjason

Hey guys, I hate to reply to my own post for fear of spamming but I
was hoping someone had the time to take a look at my initial questions
above, as I'm still at a standstill. 8(

On Aug 7, 12:11 pm, xbsjason  wrote:
> Hello all,
>
> My question is two-fold. I finally figured out agrepsearch and
> replacepatternthat suits my needs. Its a really simple one, but a
> huge step forward for me.
>
> SEARCHGREP
> ^([^\t]+)\t([^\t]+)$
>
> REPLACE WITH
> \2.\rNote: \1\r
>
> So my question is this... Is it possible to create a replacepattern
> that will change the case for \2 to Capitalized case, but only if the
> included words are 4 or more letters? As an example I have this:
>
> Model1495 \t Base cabinet, hardware, and related accessories
>
> Which, when run through mygrepsearch and replace becomes this:
>
> Base cabinet, hardware, and related accessories.
> Note: Model1495
>
> But I'd like it to become this (note the capitalized case for words 
> inpattern2 longer than 4 characters):
>
> Base Cabinet, Hardware, and Related Accessories.
> Note: Model1495
>
> Is this possible?
>
> Next question, if I have a list of item names, can I quickly create a
> text file for each of them?
>
> Say my list is simple each item on a new line like so...
>
> Item 1
> Item 2
> Item 3
>
> and I want Item1.txt, Item2.txt, Item3.txt
>
> Thanks for the time.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Auto-Close elements

2009-08-17 Thread Moop

Is there a way to get BBEdit to auto-close elements? Like if I'm
writing an XML/HTML document, and type  it should automatically
insert  for me. I know that I can do something like this when
writing HTML, but custom XML doesn't have this feature.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Run Unix scripts without changing content?

2009-08-17 Thread Carlton Gibson


On 17 Aug 2009, at 10:05, Maarten Sneep wrote:

>
> On Mon, 17 Aug 2009 09:49:56 +0100, Carlton Gibson
>  wrote:
>> On 17 Aug 2009, at 09:36, Maarten Sneep wrote:
>>
>>>
>>> On Mon, 17 Aug 2009 09:14:44 +0100, Carlton Gibson wrote:
>>>
 You can use AppleScript from within your shell script to query  
 BBEdit
 for the information you need.
>>>
>>> No, you can't. BBEdit does not process apple events while a unix
>>> command
>>> is running. Trying to do so will result in a timeout error for the
>>> osascript command, as BBEdit never replies.
>>
>> I'm just learning all this, as I need exactly the same kind of
>> functionality that was asked for, but running the example I gave  
>> below
>> in the terminal works exactly as expected. Can you give an example
>> that should work but doesn't, 'cause as I say I'm just learning but
>> I've not had any problems.
>
> It does work from the terminal, because it isn't BBEdit that is  
> calling
> the script. As soon as you install that script in BBEdit's #! menu,  
> you
> will have yourself an infinite loop, or rather a race condition.  
> Since the
> OP was asking about filters (I think), he intends to run from the #!  
> menu,
> and will run into trouble. Of course, not running as a filter, but  
> as a
> script instead may be the right answer.

Brilliant. I just put the script in the Unix _Scripts_ folder and sure  
enough it hangs. -- Separate utilities outside BBEdit it is then...  
Thanks!



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Run Unix scripts without changing content?

2009-08-17 Thread Maarten Sneep

On Mon, 17 Aug 2009 09:49:56 +0100, Carlton Gibson
 wrote:
> On 17 Aug 2009, at 09:36, Maarten Sneep wrote:
> 
>>
>> On Mon, 17 Aug 2009 09:14:44 +0100, Carlton Gibson wrote:
>>
>>> You can use AppleScript from within your shell script to query BBEdit
>>> for the information you need.
>>
>> No, you can't. BBEdit does not process apple events while a unix  
>> command
>> is running. Trying to do so will result in a timeout error for the
>> osascript command, as BBEdit never replies.
> 
> I'm just learning all this, as I need exactly the same kind of  
> functionality that was asked for, but running the example I gave below  
> in the terminal works exactly as expected. Can you give an example  
> that should work but doesn't, 'cause as I say I'm just learning but  
> I've not had any problems.

It does work from the terminal, because it isn't BBEdit that is calling
the script. As soon as you install that script in BBEdit's #! menu, you
will have yourself an infinite loop, or rather a race condition. Since the
OP was asking about filters (I think), he intends to run from the #! menu,
and will run into trouble. Of course, not running as a filter, but as a
script instead may be the right answer.

Maarten

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Run Unix scripts without changing content?

2009-08-17 Thread Carlton Gibson


On 17 Aug 2009, at 09:36, Maarten Sneep wrote:

>
> On Mon, 17 Aug 2009 09:14:44 +0100, Carlton Gibson wrote:
>
>> You can use AppleScript from within your shell script to query BBEdit
>> for the information you need.
>
> No, you can't. BBEdit does not process apple events while a unix  
> command
> is running. Trying to do so will result in a timeout error for the
> osascript command, as BBEdit never replies.

I'm just learning all this, as I need exactly the same kind of  
functionality that was asked for, but running the example I gave below  
in the terminal works exactly as expected. Can you give an example  
that should work but doesn't, 'cause as I say I'm just learning but  
I've not had any problems.

TIA
Carlton


> If the script is not called
> from the BBEdit interface, but from a global scripting menu, then  
> BBEdit
> will respond as expected. However, this means that the script is not  
> in the
> standard menu structure of BBEdit.
>
>> The key is using the `osascript` command.
>>
>> As an example (without an error checking) this outputs the path of  
>> the
>> current file:
>>
>> getDoc='tell application "BBEdit"
>>  set a to file of text document 1
>>  set p to POSIX path of a
>> end tell';
>> BB_DOC_PATH=`osascript -e "$getDoc"`;
>> echo $BB_DOC_PATH;
>>
>> The backticks capture the output of the osascript call into the
>> BB_DOC_PATH variable. The -e flag takes an inline script; I think -s
>> is the one to specify a separate script file, check the man page.
>> (Given issues with escape sequences, both to the shell and the
>> applescript component itself, using an external script can be a lot
>> easier.)
>
> A heredoc can also be very helpful ( http://en.wikipedia.org/wiki/Heredoc
> ), but only in cases where osascript can actually be used.
>
> Maarten
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Run Unix scripts without changing content?

2009-08-17 Thread Maarten Sneep

On Mon, 17 Aug 2009 09:14:44 +0100, Carlton Gibson wrote:

> You can use AppleScript from within your shell script to query BBEdit  
> for the information you need.

No, you can't. BBEdit does not process apple events while a unix command
is running. Trying to do so will result in a timeout error for the
osascript command, as BBEdit never replies. If the script is not called
from the BBEdit interface, but from a global scripting menu, then BBEdit
will respond as expected. However, this means that the script is not in the
standard menu structure of BBEdit.

> The key is using the `osascript` command.
> 
> As an example (without an error checking) this outputs the path of the  
> current file:
> 
> getDoc='tell application "BBEdit"
>   set a to file of text document 1
>   set p to POSIX path of a
> end tell';
> BB_DOC_PATH=`osascript -e "$getDoc"`;
> echo $BB_DOC_PATH;
> 
> The backticks capture the output of the osascript call into the  
> BB_DOC_PATH variable. The -e flag takes an inline script; I think -s  
> is the one to specify a separate script file, check the man page.  
> (Given issues with escape sequences, both to the shell and the  
> applescript component itself, using an external script can be a lot  
> easier.)

A heredoc can also be very helpful ( http://en.wikipedia.org/wiki/Heredoc
), but only in cases where osascript can actually be used.

Maarten

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---



Re: Run Unix scripts without changing content?

2009-08-17 Thread Carlton Gibson
On 14 Aug 2009, at 11:23, skillzero wrote:
> Is there a way to run a non-filter Unix script that has info about the
> current window? I'd like to be able to run a Unix script with access
> to BB_DOC_PATH, BB_DOC_SELSTART, BB_DOC_SELEND, etc., but I don't want
> to modify the text of the window (as a filter does). For example, I
> want to have a script that does a 'git difftool' (which I've
> configured to use bbdiff) on the current window to show a side-by-side
> diff. Another thing I want is to select some text and do 'git blame'
> on the selected lines and show them in the new window.

You can use AppleScript from within your shell script to query BBEdit  
for the information you need.

The key is using the `osascript` command.

As an example (without an error checking) this outputs the path of the  
current file:

getDoc='tell application "BBEdit"
set a to file of text document 1
set p to POSIX path of a
end tell';
BB_DOC_PATH=`osascript -e "$getDoc"`;
echo $BB_DOC_PATH;

The backticks capture the output of the osascript call into the  
BB_DOC_PATH variable. The -e flag takes an inline script; I think -s  
is the one to specify a separate script file, check the man page.  
(Given issues with escape sequences, both to the shell and the  
applescript component itself, using an external script can be a lot  
easier.)

I hope this helps.

Regards,
Carlton
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a specific feature request or would like to report a suspected (or 
confirmed) problem with the software, please email to "supp...@barebones.com" 
rather than posting to the group.
-~--~~~~--~~--~--~---