Doesn't need wc
.
Set $IFS
to a tab temporarily on the line ahead of a read
.
That will exclude spaces (c.f. "a b c").
Read into an array, and loop each.
Test for length > 8000 and behave accordingly.
Here's a quick example you should be able to adapt.
$: IFS=" " read -a lst < in
$: for x in "${lst[@]}"
> do l="${#x}"
> if (( l > 8000 ))
> then x='<too long>'
> fi
> printf "'%s' = %d\n" "$x" "$l"
> done
'hi' = 2
'a b c' = 5
'apple' = 5
'<too long>' = 10000
'toast' = 5
If you are processing a really big file, write it in awk
or perl
for better performance.