I\'m looking for a simple way to find the length of the longest line in a file. Ideally, it would be a simple bash shell command instead of a script.
If you are using MacOS and are getting this error:
wc: illegal option -- L you dont need to install GNU sipmly do this.
If all you want to do is just get the count of the characters in the longest line of the file and you are using OS X run:
awk '{print length}' "$file_name" | sort -rn | head -1
Something like this;
echo "The longest line in the file $file_name has $(awk '{print length}' "$file_name" | sort -rn | head -1) characters"
Outputs:
The longest line in the file my_file has 117 characters