Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-29-2013, 02:49 PM   #1
Registered: Sep 2012
Posts: 372

Rep: Reputation: 1
Problem with space padding

I "thought" this was how to pad spaces in front of a line:
spaces=" "
pad=`echo "$spaces" | cut -c $pdl`
echo "B${pad}E"
but I get:
I've tried with a constant instead of "$pdl" and get the same thing.
I "THINK" I have used this before but I am not able to get the proper pad length created. Use of printf had similar problems. Does anyone see my mistake. I would like to find a correction rather than an alternate padding solution since I feel certain I've used this before.
Old 10-29-2013, 03:18 PM   #2
Senior Member
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
use printf

printf "B%12sE\n"
or for more fun
printf "%*s%*s%s\n" $(( ${COLUMNS} / 2 )) "B" $((12+1)) "E"
Centre="This is in centre"
printf "%*s\n" $(( (${COLUMNS}+${#Centre}) / 2 )) "$Centre"
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
tar: File shrank,padding with zeros fahedakhter Linux - Newbie 3 06-24-2011 01:29 PM
[SOLVED] Padding jffs2 rootfs image njozwiak Linux - Embedded & Single-board computer 1 03-23-2011 01:55 PM
Padding a number ahmedb72 Linux - Newbie 2 07-07-2009 05:33 AM
Date format lost padding OldGaf Programming 2 05-01-2008 07:25 PM
string padding and replacement functions George2 Programming 4 11-19-2006 02:09 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration