I have a file that is unformatted, I want to put a new line after every 100th character and delete any other new lines so that the file looks with a constant width and readable
This piece of code helps to read all the lines.
while read LINE
do
len=${#LINE}
echo "Line length is : $len"
done < $file
but how to do the same for characters
The idea should have something like this: (just an example, it may have syntax errors, not yet implemented)
while read ch
do
chcount++
if [ "$chcount" -eq "100" && "$ch"!="\n" ]
then
echo -e "\n"
elif [ "$ch"=="\n" ]
then
ch=" " $replace it with space
fi
done < $file
I study bash, so please go calmly!
source
share