I've found this thread:
How to insert a new line character after a fixed number of characters in a file
but the answers there unfortunately don't help me.
I have this huge string $temp
that I want to have cut off after a specific amount of characters (e.g. 20) to match it with the line above. After that number of characters there should be added a \n
and in the end the formatted string should be inserted into a variable. There should be no cutting if the length of the string is < the number.
Right now I'm sticking to
sed -e "s/.\{20\}/&\n/g" <<< $temp
but it doesn't work. Instead of adding \n
it's adding spaces.