Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash - cut " " from end of variable


    I have a variable zamik, which is concatenated from a and b
    So it looks something like:
    Code:
    a="|   "  
    b="    ".
     "|          |                  |                         ".
    I'd like to cut last empty spaces, so it would look like:
    Code:
     "|          |                  |".
    I tried many things, like:
    zamik=${zamik#*|}
    zamik=${zamik%|*}
    zamik=${zamik%%\x20}
    zamik=${zamik%"|"}

    but none works...

  2. #2
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    480
    have you tried "cut"?

    cut -b -12 <text

    supposing you want to retain 12 characters.
    the sun is new every day (heraclitus)

  3. #3
    I solved it using local variables (i was adding $a and $b in recursive calls).

    I couldn't use cut because I didn'n know how many characters exactly I want to keep.

    Thanks anyway.

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •