The problem statement, all variables and given/known data:
I have to make a tool that is centering the given text by the screen width or given parameter.
I have no idea how to write this script. Can anyone make it for me ir at least help?
Relevant commands, code, scripts, algorithms:
None
The attempts at a solution (include all code and scripts):
None
Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Vilnius University, Vilnius, Lithuania, A. Mita�inas, 2nd course
It's not a serious task, it is worth just 0,5 of 10. Of course, if I get the code, I would analyse it all and learn every single symbol meaning. But I don't even know how to start writing the code. There was only one practise lecture these year and the lecturer didn't really tought us anything. And there he gave us the task.
Please, help
You can center the text by using the man printf (POSX) utility with the %s format specification. How far you have to pad it would depend on the length of the string, which you can get either through man wc (POSIX) or, if you're using bash, by the parameter expansion ${#variable}.
The screen size can be read from the man stty (POSIX) utility, by running it as stty size .
The formula for the padding itself is just (screen width - length of text) / 2.
Hi, you cannot do this with a sed statement like that. You first have to calculate how many lines to skip and how many spaces to pad. Then skip the number of lines and then pad every line at the front before writing it.