Try:
awk '{ print length, $0 }' testfile | sort -n | cut -d" " -f2- | head -1
The idea is to use awk to print the length of each line first. This will appear as:
echo "This is a line of text" | awk '{print length, $0}'
22 This is a line of text
Then, use the character count to sort the lines by sort, cut to get rid of the count and head to keep the first line (the one with the least characters). You can of course use tail to get the line with the most characters in this case.
(This was adopted from this answerthis answer)