Skip to main content
deleted 95 characters in body
Source Link
Socowi
  • 645
  • 6
  • 15

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Here we assume you have the GNU versions of grep which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of a path so we can use it to separate paths.
If you don't have the GNU version you can create something that delimits paths by newlines under the assumption that no path contains a newline character. Replace \0 with \n and remove the -z flag.

If you change …_*.txt to something else you may also have to update the sed command.

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Here we assume you have the GNU versions of grep which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of path so we can use it to separate paths.
If you don't have the GNU version you can create something that delimits paths by newlines under the assumption that no path contains a newline character. Replace \0 with \n and remove the -z flag.

If you change …_*.txt to something else you may also have to update the sed command.

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Here we assume you have the GNU versions of grep which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of a path so we can use it to separate paths.
If you don't have the GNU version you can create something that delimits paths by newlines under the assumption that no path contains a newline character. Replace \0 with \n and remove the -z flag.

If you change …_*.txt to something else you may also have to update the sed command.

deleted 291 characters in body
Source Link
Socowi
  • 645
  • 6
  • 15

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files or lines in these files?][of files] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Count the lines for each of these files

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
wc --files0-from=- -l

Count the total number of lines for all of these files together

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
xargs -0 cat | wc -l

Here we assume you have the GNU versions of grep, xargs, and wc which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of path so we can use it to separate paths.
If you don't have the GNU versionsversion you can create something that delimits paths by newlines. Remove under the -z/-0 flags, replaceassumption that no path contains a newline character. Replace \0 with \n and so onremove the -z flag.

If you change …_*.txt to something else you may also have to update the sed command.

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files or lines in these files?] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Count the lines for each of these files

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
wc --files0-from=- -l

Count the total number of lines for all of these files together

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
xargs -0 cat | wc -l

Here we assume you have the GNU versions of grep, xargs, and wc which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of path so we can use it to separate paths.
If you don't have the GNU versions you can create something that delimits paths by newlines. Remove the -z/-0 flags, replace \0 with \n and so on.

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Here we assume you have the GNU versions of grep which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of path so we can use it to separate paths.
If you don't have the GNU version you can create something that delimits paths by newlines under the assumption that no path contains a newline character. Replace \0 with \n and remove the -z flag.

If you change …_*.txt to something else you may also have to update the sed command.

added 415 characters in body
Source Link
Socowi
  • 645
  • 6
  • 15

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files or lines in these files?] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Count the lines for each of these files

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
wc --files0-from=- -l

Count the total number of lines for all of these files together

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
xargs -0 cat | wc -l

Here we assume you have the GNU versions of grep, xargs, and wc which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of path so we can use it to separate paths.
If you don't have the GNU versions you can create something that delimits paths by newlines. Remove the -z/-0 flags, replace \0 with \n and so on.

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files or lines in these files?] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Count the lines for each of these files

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
wc --files0-from=- -l

Count the total number of lines for all of these files together

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
xargs -0 cat | wc -l

Don't use a loop at all. Instead, list all files and use a command like grep or akw to filter out the files between start and stop. printf won't have the problem Argument list too long as it is a bash built-in.

count the total number [of files or lines in these files?] that exists between $start and $stop

Count the files

printf '%s\0' /home/me/*/file_*.txt |
grep -cEzf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/')

Count the lines for each of these files

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
wc --files0-from=- -l

Count the total number of lines for all of these files together

printf '%s\0' /home/me/*/file_*.txt |
grep -Ezf <(seq "$start" "$stop" | sed 's/.*/_&\.txt$/') |
xargs -0 cat | wc -l

Here we assume you have the GNU versions of grep, xargs, and wc which can handle null bytes. This is important to process paths safely. The null byte is the only character which cannot be part of path so we can use it to separate paths.
If you don't have the GNU versions you can create something that delimits paths by newlines. Remove the -z/-0 flags, replace \0 with \n and so on.

Source Link
Socowi
  • 645
  • 6
  • 15
Loading