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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.