So, i'm using bash to read a file (that has no newlines, space or tab).
Something like this:
aababcbbcbckqkkqkqhddhkehkjhqkjhsdk
skjhqkdjhqkzdhkzhdkjqzhdhqkjhzdkqzh
though there is a newline in this example, there isn't on the data i'm working on... So i found that, since everything was technically seen as on "the same line" (since there isn't any newline or any delimiter i could use), i tried to read every Nth chars:
while read -N129999 character; do
program "$character"
done < <(cat file | tr -d '\n')
(I'm aware of the "useless use of cat")
The number i'm using here is just the maximum i found that i could make read
use, (which also i prefer doing since it process the file faster)
The program
here is just an example and for the sake of illustration.
And i'm purposely removing newline, tabs and space on the aforementioned data.
Now while what i provided work, it doesn't quite work for the last part of the file, which contain less than the aforementioned number...and while i'm aware that, if there was a delimiter provided to IFS
, the -n option could continue after that instead of ignoring the rest of file which doesn't fit the range of characters...
How do i (in bash, sed, or any posix tools?) read every Nth range of characters, while including the rest of the file/input, which doesn't fit that range?
perl -e 'system("somecmd", $a) while (sysread STDIN, $a, 9999)' < <(...)
Bash'sread
only ever reads 128 bytes at a time for some reason (even with-N
, I tested), so it can suffer from a bit more overhead than most utils there. I have no idea if that makes any meaningful difference here, though.read
accept no more than 129999 characters though, probably related). And yes, it does have a meaningful difference i believe (at least for me), since, more chars read, faster processing!