reverted to tail|head|wc pattern to find EOL to avoid storing multi/NUL bytes in bash strings