Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2

    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
    tpl
    tpl is offline
    Linux User
    Join Date
    Jan 2007
    Location
    cleveland
    Posts
    477
    have you tried "cut"?

    cut -b -12 <text

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

  3. #3
    Just Joined!
    Join Date
    Apr 2011
    Posts
    2
    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.

Posting Permissions

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