Javatpoint Logo
Javatpoint Logo

Linux tr

The command 'tr' stands for 'translate'. It is used to translate, like from lowercase to uppercase and vice versa or new lines into spaces.

Syntax:

Change Case

The 'tr' command can change case.

Syntax:

Example:

Linux tr Filters1

Look at the above snapshot, all p,r,c,u are converted into upprecase P,R,C,U.

Remove New Lines

To write all the lines into a single line we have to translate all new lines into spaces.

Syntax:

Example:

Linux tr Filters2

tr Options

  • tr -s : The 'tr -s' command squeezes the occurence of multiple characters into one.
  • Syntax:

    Example:

    Linux tr Filters3

    Look at the above snapshot, command "cat jtp.txt | tr -s 'l'" has squeezed all the letters 'l' into one and command "cat spaces.txt | tr -s ' '" has squeezed all the spaces into single space.

  • tr rot13: This command encrypts the text. It is case-sensitive.
  • Example:

    Linux tr Filters4

    Look at the above snapshot, all the letters are encrypted according to the command. But letter 'A' and 'M' are not encrypted as they are in upper case.

  • tr -d: The 'tr -d' command is used to delete characters.
  • Syntax:

    Example:

    Linux tr Filters5

    Look at the above snapshot, all the 'o' letters are deleted from the file 'exm.txt'.

Next TopicLinux Uniq




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA