Reputation: 43
I have the following code reading lines from a file and outputting a count:
while read -u 3 -r line; do
echo $i
i=$(( i + 1))
done 3<"$IN_FILE"
(I want to do more inside the loop, but this illustrates the issue).
This loop never ends for me. My IN_FILE
contains 28.8M lines (as confirmed with wc -l
), but it just keeps going and is outputting counts up to ~35M before I manually kill it. If I use head/tail to create a small sample of this file, it runs just fine and terminates as expected.
Does anyone have any idea what could cause this? Is there some special character that my file might contain that would cause the redirect to go into a loop?
If it's relevant, I'm running this bash script in Mac OS X terminal...
Thanks.
Upvotes: 2
Views: 453
Reputation: 1334
Maybe try using split -l 1000000 $IN_FILE
to break it up into 29 files and see if any of those has the weird behavior?
Upvotes: 1