- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- print formatted text to center of a text terminal
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 10:45 AM
08-19-2003 10:45 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 10:56 AM
08-19-2003 10:56 AM
SolutionYou can do something like this:
#!/usr/bin/sh
MSG="This message is centered!"
MSZ=${#MSG}
COL=`echo "(80-${MSZ})/2"|bc`
clear
tput cup 12 ${COL}
echo ${MSG}
tput cup 23 0
exit 0
Note that the string of text will be centered horizontally at row-12. See the man pages for 'tput' for more information.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:04 AM
08-19-2003 11:04 AM
Re: print formatted text to center of a text terminal
#!/usr/bin/sh
center_it()
{
if [[ ${#} -ne 1 ]]
then
echo "Function center_it expects exactly 1 arg" >&2
return 255
fi
WORDS=${1}
shift
WIDTH=$(tput cols)
LEN=${#WORDS}
SPACES=$(( (${WIDTH} - ${LEN}) / 2 ))
I=1
while [[ ${I} -le ${SPACES} ]]
do
echo " \c"
I=$((${I} + 1))
done
echo "${WORDS}"
return 0
} # center_it
center_it "Turnip grrens is good"
That should do it if my typing is ok.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:08 AM
08-19-2003 11:08 AM
Re: print formatted text to center of a text terminal
eg:
line1
line2 is longer
line3 is longest line
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:10 AM
08-19-2003 11:10 AM
Re: print formatted text to center of a text terminal
has some suggestions. I answered:
# perl -e'$msg="@ARGV";printf"%*s%s\n",(($ENV{COLUMNS}||80)-length$msg)/2,"",$msg' Your message
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:18 AM
08-19-2003 11:18 AM
Re: print formatted text to center of a text terminal
To handle multiple lines, simply create a shell function (as Clay has shown) that is passed the line (text string) that you want centered. If you want to place the line at a particular screen row, create or amend the function to understand the receipt of a second argument defining the row.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:18 AM
08-19-2003 11:18 AM
Re: print formatted text to center of a text terminal
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:28 AM
08-19-2003 11:28 AM
Re: print formatted text to center of a text terminal
# perl -e'printf"%*s%s\n",(($ENV{COLUMNS}||80)-length)/2,"",$_ for@ARGV' "Line 1" "Longer line 2" "ln3"
The left aligned block centered something like
# perl -e'map{length($_)>$l and $l=length}@ARGV;$l=(($ENV{COLUMNS}||80)-$l)/2;printf"%*s%s\n",$l,"",$_ for@ARGV' "Line 1" "Longer line 2" "ln3"
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 11:32 AM
08-19-2003 11:32 AM
Re: print formatted text to center of a text terminal
Could you pls explain more.
I did not get an output from Clay's script. Pls advise what did I miss.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2003 01:20 PM
08-19-2003 01:20 PM
Re: print formatted text to center of a text terminal
for example-
adjust -c myfile
This will center each text line of "myfile" on the screen.
HTH
-- Rod Hills