Hey fiomba,
Good to hear your learning scripting. Unfortunately, I can only help with some of your question, as some are in areas I haven't worked with, and I have to leave soon.

I can give you an idea of how I would trim newlines, but it doesn't use sed (I'm sure there's a way, but I find tr faster).
cat file.txt | tr -d "\n"
Check out the man page on tr, it's a pretty standard command, so it should be fairly portable.
If you wanted to put this into a variable, all you would need to do is set it to execute in a subshell, and have the variable equal that.
textvariable=$(cat file.txt | tr -d "\n")
By using the $( ) form, commands inside will be executed as shell commands before they are used in the script.
Hope these tidbits help you on your way, I know there is a command to count characters, but I've never used it in a script so I forgot it