Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

unix shellscript: echo question

  • 20-10-2005 9:35am
    #1
    Registered Users, Registered Users 2 Posts: 7,497 ✭✭✭


    I'm trying to print an amount of time like so;

    2H 43M
    12H 4M
    25H 25M
    1H 4M

    The problem is i want to have the number of characters in each item the same. So ideally it will look like this:

    02H 43M
    12H 04M
    25H 25M
    01H 04M

    How do i get the script to fill in the spaces with 0s but not let the time exceed a certain number of characters?

    Also when I'm printing echo like so;

    echo -e "$high \t $low \t"

    it can look like this:

    314341 432344
    32 432433
    32423434 342343
    3243 3432434


    the tabs don't seem to want to align the text. any ideas?

    thanks in advance.


Comments

  • Registered Users, Registered Users 2 Posts: 2,426 ✭✭✭ressem


    I'd suggest using printf instead of echo.
    http://www.mkssoftware.com/docs/man1/printf.1.asp
    It has pretty much the same formatting functionality as the c version

    E.g.
    printf "%09uH %05uM %03uS \n" 2 43 0
    Outputs
    000000002H 00043M 000S
    The 0 following each % indicates that you want 0 padding, and the next number is the width that the field will fill.

    %u indicates unsigned integers.

    So you'd be using "%02uH %02uM" 2 83


  • Registered Users, Registered Users 2 Posts: 7,497 ✭✭✭quarryman


    thanks ressem that's a great help


Advertisement