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

    Does anyone know what tr -c is supposed to do ?

    I've read the man page and I'm not clear what it means for the
    characters in SET1 to be "complemented".I did some experiments
    which gave me some idea but also confused me.
    My input ( $ is the prompt ):
    $ tr -c 12345 a
    Does anyone know what the algorithm is supposed to be ?

  2. #2
    It's complementing the sense of the match - ie translating if the input characters are not in SET1.

  3. #3
    Can you expand on that ? What kind of translation does it do ?

  4. $spacer_open
  5. #4

    tr is translating?

    I don't think it translates at all: it would ask in what langage
    you're writing and in what langage you want the translation
    to be if it did, wouldn't it? Plus the word to be translated,
    that would be 3 compulsory parameters. It only wants 2

    I tried

    tr "help" "french" and it just hanged.


  6. #5

  7. #6

    -c means translate every character that is NOT in string1 to string2

    For example, suppose you wanted to make every non-alphanumeric character visible in a file, make them show as a # character:

     tr -c '&#91;A-Z&#93;&#91;a-z&#93;&#91;0-9&#93;' '&#91;#*&#93;'  < myfile
    All the spaces, etc., all turn into # characters.

    Suppose you wanted to remove all characters that were not alphanumeric:
     tr -cd  "&#91;A-Z&#93;&#91;a-z&#93;&#91;0-9&#93;"  < myfile

  8. #7
    Is the '[#*]' part necessary ? On my machine typing tr -c '[A-Z][a-z][0-9]' # seems
    to produce the same results as tr -c '[A-Z][a-z][0-9]' '[#*]'
    Also what happens if the second string has more than one characters ?
    On my machine only the last one seems to be used. (I'm always talking about the -c option.)

  9. #8
    tr works on a per character basis. Not on two characters - then you want sed.

    Yes the # would also work for GNU tr.

  10. #9
    I was thinking that if I type tr -c '[A-Z][a-z][0-9]' #@ for example
    then the 1st non-alphanumeric character would be replaced by
    # , the 2nd by @ , the 3rd by # again and so on.

    But anyway , thanks for the info.

Posting Permissions

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