Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7165157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:11:39+00:00 2026-05-28T14:11:39+00:00

Given a text, $txt , how could I left justify it to a given

  • 0

Given a text, $txt, how could I left justify it to a given width in Bash?

Example (width = 10):

If $txt=hello, I would like to print:

hello     |

If $txt=1234567890, I would like to print:

1234567890|
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:11:40+00:00Added an answer on May 28, 2026 at 2:11 pm

    You can use the printf command, like this:

    printf "%-10s |\n" "$txt"
    

    The %s means to interpret the argument as string, and the -10 tells it to left justify to width 10 (negative numbers mean left justify while positive numbers justify to the right). The \n is required to print a newline, since printf doesn’t add one implicitly.

    Note that man printf briefly describes this command, but the full format documentation can be found in the C function man page in man 3 printf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, say I have a text file example.txt that reads: I like dogs.
Given a large text block from a WYSIWYG like: Lorem ipsum dolor sit amet,
given a plain text file, how can I do, using bash, awk, sed, etc,
given a plain text document with several lines like: c48 7.587 7.39 c49 7.508
Given a couple of simple tables like so: create table R(foo text); create table
I was given this text file, call stock.txt, the content of the text file
In the example given below, I was expecting the line $a=b in the todel.txt
Given a text file, how would I go about reading an arbitrary line and
Given an HTML link like <a href=urltxt class=someclass close=true>texttxt</a> how can I isolate the
I'm looking for a method that computes the line number of a given text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.