Searching files by number of lines in the file

2018-12-10 Thread Philippe Carly
I would like to find multiple files (I know how to do that) 
that don' have a specific number of lines (this I don't know).

More specifically, I have a directory which contains a large number of 
subdirectories, each containing (among other things) a fileinfo.php file.
I now that this fileinfo.php should have N lines. And I am trying to locate 
files that have more or less than N lines to search for potential problems.

thanks for your help.

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-10 Thread 'Holger Bartel' via BBEdit Talk
Hi, 

Absolutely untested, but maybe something like counting number of line ends 
followed by a line break/return as in search for: $\r{number_of_lines} or 
$\n{number_of_lines} could work? Grep needs to be turned on for that, in case 
that’s new. 

I think $\n{min, max} should find those that have less or more lines if I’m not 
mistaken. 

Hope this helps,
Holger

> On 10 Dec 2018, at 8:26 PM, Philippe Carly  wrote:
> 
> I would like to find multiple files (I know how to do that) 
> that don' have a specific number of lines (this I don't know).
> 
> More specifically, I have a directory which contains a large number of 
> subdirectories, each containing (among other things) a fileinfo.php file.
> I now that this fileinfo.php should have N lines. And I am trying to locate 
> files that have more or less than N lines to search for potential problems.
> 
> thanks for your help.
> 
> -- 
> This is the BBEdit Talk public discussion group. If you have a 
> feature request or need technical support, please email
> "supp...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to bbedit+unsubscr...@googlegroups.com.
> To post to this group, send email to bbedit@googlegroups.com.
> Visit this group at https://groups.google.com/group/bbedit.

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-10 Thread Sam Hathaway
I don’t know how to do it with BBEdit, but this shell command will 
work:


`find /path/to/files -name fileinfo.php -exec sh -c 'test `cat {} | wc 
-l` -ne N’ \; -print`


Replace `/path/to/files` with the path to your directory and `N` with 
your “N”.


Hope this helps.
-sam

On 10 Dec 2018, at 7:26, Philippe Carly wrote:


I would like to find multiple files (I know how to do that)
that don' have a specific number of lines (this I don't know).

More specifically, I have a directory which contains a large number of
subdirectories, each containing (among other things) a fileinfo.php 
file.
I now that this fileinfo.php should have N lines. And I am trying to 
locate
files that have more or less than N lines to search for potential 
problems.


thanks for your help.

--
This is the BBEdit Talk public discussion group. If you have a
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
---
You received this message because you are subscribed to the Google 
Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to bbedit+unsubscr...@googlegroups.com.

To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


--
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-11 Thread Philippe Carly
Hello Holger,
thank you for your feedback...
Unfortunately BBEdit doesn't seem to understand the {x,y} bit of the GREP 
search
cheers
Philippe

On Monday, December 10, 2018 at 3:50:21 PM UTC+1, Hoger November wrote:
>
> Hi, 
>
> Absolutely untested, but maybe something like counting number of line ends 
> followed by a line break/return as in search for: $\r{number_of_lines} or 
> $\n{number_of_lines} 
> could work? Grep needs to be turned on for that, in case that’s new. 
>
> I think $\n{min, max} should find those that have less or more lines if 
> I’m not mistaken. 
>
> Hope this helps,
> Holger
>
> On 10 Dec 2018, at 8:26 PM, Philippe Carly  > wrote:
>
> I would like to find multiple files (I know how to do that) 
> that don' have a specific number of lines (this I don't know).
>
> More specifically, I have a directory which contains a large number of 
> subdirectories, each containing (among other things) a fileinfo.php file.
> I now that this fileinfo.php should have N lines. And I am trying to 
> locate files that have more or less than N lines to search for potential 
> problems.
>
> thanks for your help.
>
> -- 
> This is the BBEdit Talk public discussion group. If you have a 
> feature request or need technical support, please email
> "sup...@barebones.com " rather than posting to the group.
> Follow @bbedit on Twitter: 
> --- 
> You received this message because you are subscribed to the Google Groups 
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to bbedit+un...@googlegroups.com .
> To post to this group, send email to bbe...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/bbedit.
>
>

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-11 Thread Sam Hathaway

Folks,

Philippe pointed out that my mail client may havr munged the quotes in that 
command line. It should be:


find /path/to/files -name fileinfo.php -exec sh -c 'test `cat {} | wc -l` 
-ne N' \; -print


I should have run it through BBEdit's useful "Straighten Quotes" command 
before sending! Sorry for the confusion.

-sam

On December 10, 2018 9:58:47 AM "Sam Hathaway"  
wrote:



I don’t know how to do it with BBEdit, but this shell command will
work:

`find /path/to/files -name fileinfo.php -exec sh -c 'test `cat {} | wc
-l` -ne N’ \; -print`

Replace `/path/to/files` with the path to your directory and `N` with
your “N”.

Hope this helps.
-sam

On 10 Dec 2018, at 7:26, Philippe Carly wrote:


I would like to find multiple files (I know how to do that)
that don' have a specific number of lines (this I don't know).


More specifically, I have a directory which contains a large number of
subdirectories, each containing (among other things) a fileinfo.php
file.
I now that this fileinfo.php should have N lines. And I am trying to
locate
files that have more or less than N lines to search for potential
problems.


thanks for your help.


--
This is the BBEdit Talk public discussion group. If you have a
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
---
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


--
This is the BBEdit Talk public discussion group. If you have a
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
---
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an 
email to bbedit+unsubscr...@googlegroups.com.

To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.




--
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-11 Thread Patrick Woolsey
On 12/10/18 at 9:22 AM, bbedit@googlegroups.com ('Holger Bartel' 
via BBEdit Talk) wrote:


Absolutely untested, but maybe something like counting number 
of line ends followed by a line break/return as in search for: 
$\r{number_of_lines} or $\n{number_of_lines} could work? Grep 
needs to be turned on for that, in case that’s new.
I think $\n{min, max} should find those that have less or more 
lines if I’m not mistaken.


and on Tue, 11 Dec 2018 03:00:28 -0800 (PST), 
philippe.ca...@gmail.com (Philippe Carly) wrote:


Unfortunately BBEdit doesn't seem to understand the {x,y} bit 
of the GREP search



For reference, BBEdit does indeed support the { }-style 
quantifiers as described in the "Quantifiers Repeat Subpatterns" 
in Chapter 8 of the PDF manual (see page 179 in the latest edition).


I regret however that the suggested search pattern of "$\n{min, 
max}" will not do what you're after[*], nor is there any direct 
way to limit a multi-file search to files containing some given 
number of lines.


In order to accomplish that, you'll need to pre-filter the files 
and pass only those of the desired size to BBEdit for searching, 
e.g. in a manner similar to Sam Hathaway's post.


[*: This pattern will instead just match the next run of between 
'min' and 'max' line feeds (i.e. consecutive empty lines) 
following a line break.]



Regards,

 Patrick Woolsey
==
Bare Bones Software, Inc. 

--
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-11 Thread Rich Siegel
On 12/10/18 at 7:26 AM, philippe.ca...@gmail.com (Philippe 
Carly) wrote:


More specifically, I have a directory which contains a large 
number of subdirectories, each containing (among other things) 
a fileinfo.php file.
I now that this fileinfo.php should have N lines. And I am 
trying to locate files that have more or less than N lines to 
search for potential problems.


If I am understand your description correctly, something like 
this should work:


-   search for:

^.*?\n{XXX} -- replace the "XXX" with the desired number of lines

-   turn on "Exclude Matches"

-   run your multi-file search.

This will return all files that don't have XXX lines in them.

You can add a file filter to only search "fileinfo.php" files to 
further narrow things down.


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

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


--
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-11 Thread Sam Hathaway

Rich’s pattern doesn’t work for me, but this does:

```
\A([^\r]*\r){N}\z
```

Details:

```
   match:
\A  - the beginning of the file
  (){N} - followed by exactly N of:
   [^\r]*  - zero or more non-linebreak characters
 \r- followed by a linebreak
   \z   - followed by the end of the file
```

Note that this assumes that all files end in a linebreak. If they might 
not, you need a slightly more complicated expression:


```
\A([^\r]*\r){M}[^\r]+\Z
```

Where `M` is one _less_ than your target number of lines.

Details:

```
 match:
\A- the beginning of the file
  (){M}   - followed by exactly M of:
   [^\r]*- zero or more non-linebreak characters
 \r  - followed by a linebreak
   [^\r]+ - followed by one or more non-linebreak 
characters
 \Z   - followed by the end of the file OR a 
trailing newline

```

That was fun. Thanks, all. :)
-sam

On 11 Dec 2018, at 10:45, Rich Siegel wrote:

On 12/10/18 at 7:26 AM, philippe.ca...@gmail.com (Philippe Carly) 
wrote:


More specifically, I have a directory which contains a large number 
of subdirectories, each containing (among other things) a 
fileinfo.php file.
I now that this fileinfo.php should have N lines. And I am trying to 
locate files that have more or less than N lines to search for 
potential problems.


If I am understand your description correctly, something like this 
should work:


-   search for:

^.*?\n{XXX} -- replace the "XXX" with the desired number of lines

-   turn on "Exclude Matches"

-   run your multi-file search.

This will return all files that don't have XXX lines in them.

You can add a file filter to only search "fileinfo.php" files to 
further narrow things down.


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



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

--
This is the BBEdit Talk public discussion group. If you have a feature 
request or need technical support, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- You received this message because you are subscribed to the Google 
Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to bbedit+unsubscr...@googlegroups.com.

To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


--
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email

"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.

To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.


Re: Searching files by number of lines in the file

2018-12-11 Thread Roland Küffner
Nice problem.
Rich’s patterns works for me - if I put some parentheses around the whole
pattern:

(^.*?\n){XXX}

I guess, without the pattern the quantifier only checks for the „\n“ and
you are in fact searching for a line of text followed by XXX line breaks
(aka empty lines).
-Roland

On Tue, Dec 11, 2018 at 4:45 PM Rich Siegel  wrote:

> On 12/10/18 at 7:26 AM, philippe.ca...@gmail.com (Philippe
> Carly) wrote:
>
> >More specifically, I have a directory which contains a large
> >number of subdirectories, each containing (among other things)
> >a fileinfo.php file.
> >I now that this fileinfo.php should have N lines. And I am
> >trying to locate files that have more or less than N lines to
> >search for potential problems.
>
> If I am understand your description correctly, something like
> this should work:
>
> -   search for:
>
>  ^.*?\n{XXX} -- replace the "XXX" with the desired number of lines
>
> -   turn on "Exclude Matches"
>
> -   run your multi-file search.
>
> This will return all files that don't have XXX lines in them.
>
> You can add a file filter to only search "fileinfo.php" files to
> further narrow things down.
>
> R.
> --
> Rich Siegel Bare Bones Software, Inc.
>   
>
> Someday I'll look back on all this and laugh... until they
> sedate me.
>
> --
> This is the BBEdit Talk public discussion group. If you have a
> feature request or need technical support, please email
> "supp...@barebones.com" rather than posting to the group.
> Follow @bbedit on Twitter: 
> ---
> You received this message because you are subscribed to the Google Groups
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to bbedit+unsubscr...@googlegroups.com.
> To post to this group, send email to bbedit@googlegroups.com.
> Visit this group at https://groups.google.com/group/bbedit.
>

-- 
This is the BBEdit Talk public discussion group. If you have a 
feature request or need technical support, please email
"supp...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: 
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to bbedit+unsubscr...@googlegroups.com.
To post to this group, send email to bbedit@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.