Find the answer to your Linux question:
Results 1 to 4 of 4
i have following line test=^DIBM,7028-6E1^M^D test1=YES test2=AIX: nexec "$HOST" uname -M trying to remove junk or non printable char doing following echo $test|tr -cd [ rint:] echo $test2|tr -cd [ ...
  1. #1
    Just Joined!
    Join Date
    Apr 2008
    Posts
    19

    remove junk char in shell?

    i have following line

    test=^DIBM,7028-6E1^M^D
    test1=YES
    test2=AIX: nexec "$HOST" uname -M

    trying to remove junk or non printable char doing following

    echo $test|tr -cd [rint:]
    echo $test2|tr -cd [rint:]
    echo $test3|tr -cd [rint:]


    but its giving me following

    IBME
    Y
    Blank

    instead of
    IBM,7028-6E1
    YES
    AIX: nexec "$HOST" uname -M

    Please help!!!

  2. #2
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    You could use tr to remove the garbage chars using the octal codes

    \015 for ^M

    \004 for ^D

    and strip them that way. Just use tr the same way and single quote the octal codes.

    Hope that helps

    , Mike

  3. #3
    Just Joined!
    Join Date
    Apr 2008
    Posts
    19
    Thanks Mike,

    I know that, but don't you think, we are hardcoding it for now. But if we get problem other than that then ??

  4. #4
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    How about dos2unix / unix2dos (or an equivalent program) that's written to do that. Also, depending on what your version of tr can do, this might help also

    echo $test|tr -sd [:cntrl:]

    On mine the -sd deletes all instrances of characters that match [:cntrl:]

    Hope that helps

    , Mike

Posting Permissions

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