- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Duplicating Characters
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
Discussions
Discussions
Forums
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
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
тАО07-21-2004 02:43 AM
тАО07-21-2004 02:43 AM
I want to be able to echo a set number of spaces based upon the width of the screen as set in ${LINES}, from within a ksh script.
I've tried a quick counting loop to build the text, but this seems to really slow up my script.
I know there is probably a good way to do this with awk/sed etc, but I just cannot think of the best way to do it !!
Any help will be greatly appreciated (as always !!)
Thanks,
Paul.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:10 AM
- Tags:
- printf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:13 AM
тАО07-21-2004 03:13 AM
Re: Duplicating Characters
YOU ARE A STAR !!!!!
Thanks !
Paul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:19 AM
тАО07-21-2004 03:19 AM
Re: Duplicating Characters
this will right justify your text
cat file |
while read text
do
printf '%${LINES}s\n' $text
done
#print "x" number of spaces
printf '%${x}s' " "
of course the important information of how many spaces (other then based on LINES) and where the spaces should be, you left out of your question.
maybe if you provided some sample text to illustrate what your trying to accomplish better suggestions could be provided.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:19 AM
тАО07-21-2004 03:19 AM
Re: Duplicating Characters
if it is only spaces you are after, then you are lucky, as printf from anywhere (awk, shell) can nicely do a variable length empty field:
# awk 'END{printf ("test%*stest\n",40," ")}' /dev/null
For long series of other characters PERL has a neat 'x' function
#perl -e 'print "*"x10 . "\n"'
**********
# perl -e 'print "*"x20 . "\n"'
********************
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:22 AM
тАО07-21-2004 03:22 AM
Re: Duplicating Characters
If I wanted to print hash marks instead of spaces, what would I need to change ?
Regs,
Paul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:43 AM
тАО07-21-2004 03:43 AM
Re: Duplicating Characters
the easy answer is perl, where you could do:
print "#" x $num;
but to avoiding calling perl for each line of your text, you'd want to do everything within perl or
#make a long variable with hashes
# just pick a number bigger then your going to need
myvar=$(perl -e 'print "#" x 256;')
then use printf within your shell script to truncate the variable to the length you want
printf "%{Len}s" $myvar
that way you'll only call perl once.
of course a simply while loop might be even faster then calling perl
x="#"
y=10
while (( y > 0 ))
do
x="$x$x"
y=$(( $y = 1 ))
done
# x is now a long string of #'s
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 03:59 AM
тАО07-21-2004 03:59 AM
Re: Duplicating Characters
x="$x$x"
y=$(( $y = 1 ))
should really be
x="$x$x"
y=$(( $y - 1 ))
and if your really doing some serious text formatting, using perl is the way to go. it is a feature rich tool which is so much better then the shell. i.e. shell text formatting has just implemented the printf function in the past few years, where perl was designed for formattng text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 04:04 AM
тАО07-21-2004 04:04 AM
Re: Duplicating Characters
Thanks again for the help. The text formatting part of the script is pretty minor, so I ended up cheating rather than using perl.
MYVAR="$(echo "$(printf "%${LINES}s" " ")" | sed 's/ /\#/g')"
Thanks again (to all !) for your help.
Paul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-21-2004 09:12 AM
тАО07-21-2004 09:12 AM
Re: Duplicating Characters
MYVAR="$(printf %${LINES}s ' ' | tr ' ' '#')"