Transform – the y command

The transform command is similar to the Linux tr command. The characters are translated according to the character sequence given. For example, y/ABC/abc/ will convert lowercase abc into uppercase ABC.

Here is an example:

    $ cat shopping.txt
  

The output will be:

    Product     Quantity  Unit_Price  Total_Cost
    Apple        2         3           6
    Orange       2          .8         1.6
    Papaya       2         1.5         3
    Chicken      3         5          15
    Cashew       1        10          10
    $ sed '2,4y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRS TUVWXYZ/' shopping.txt
  

The output will be:

    Product  Quantity  Unit_Price  Total_Cost
    APPLE       2        3           6
    ORANGE      2        .8          1.6
    PAPAYA      2       1.5          3
    Chicken     3       5           15
    Cashew      1      10           10
  

In this example, for lines 2, 3, and 4, all the lowercase letters are converted to uppercase letters.

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.