Bash while loop to truncate file with bad tuples
Briefly

To delete a specific number of lines from a file dynamically based on a counter, you can incorporate the variable directly into the sed command with the following syntax.
Instead of using a bash while loop, you can use sed directly to stop when encountering the first valid record, which simplifies your script greatly.
By using sed in combination with the counter, you can effectively delete the desired number of lines without iterating through the entire file.
The challenge with your while loop is that it doesn’t account for the file structure properly, leading to incorrect line lengths being calculated.
Read at SitePoint Forums | Web Development & Design Community
[
|
]