LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-29-2013, 02:49 PM   #1
waddles
Member
 
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=" "
pdl=12
pad=`echo "$spaces" | cut -c $pdl`
echo "B${pad}E"
but I get:
B E
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.
Thanks
 
Old 10-29-2013, 03:18 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
use printf

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:51 PM.

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