a feature i would like to see added to grep
Posted 10-28-2022 at 06:20 PM by Skaperen
Tags grep
a feature i would like to see added to the grep family of commands (that is, to all of them) is the ability to specify a limit of how much of the file to scan for matching patterns/expressions. this would not be like the -m NUM/--max-count=NUM option, which counts what is actually matched. the limit i want to also see is effectively a limit of the size of the file. after this much of the file has been read, grep should behave as if the file ended. this would be the number of bytes unless the letter "l" or "L" is at the end of the number, after any size multipliers ("k", "m", "g", "t", "p" or upper case variants). the letter "l" or "L" would change the unit from bytes to lines.
the reason i would like to see this is that i often want to scan my 5 million and some files for some text i expect to find in some file(s) usually only in the first 4K or so. but about a million or so files are rather large, having a wide variety of names. even if a big file will match, it generally is only going to be in the first 4K or so. a significant fraction of those large files are over a gigabyte in size (hundreds of them). i hate having such a search take over an hour. it could run faster if it would quit scanning any file with no matches when it reaches 4K (or whatever number is requested).
the reason i would like to see this is that i often want to scan my 5 million and some files for some text i expect to find in some file(s) usually only in the first 4K or so. but about a million or so files are rather large, having a wide variety of names. even if a big file will match, it generally is only going to be in the first 4K or so. a significant fraction of those large files are over a gigabyte in size (hundreds of them). i hate having such a search take over an hour. it could run faster if it would quit scanning any file with no matches when it reaches 4K (or whatever number is requested).
Total Comments 1
Comments
-
That's what head and tail are for.
Posted 10-31-2022 at 09:39 AM by GazL