10.3.4 字符转换

使用y命令可进行字符转换,其作用为将一系列字符逐个地变换为另外一系列字符,基本用法如下:


#

该命令会将file

中的O

转换为N

、L

转换为E

、D

转换为W

#

注意转换字符和被转换字符的长度要相等,否则sed

无法执行

sed 'y/OLD/NEW/' file


下面的命令演示了将数字1转换为A,2转换为B,4转换为C,5转换成D的用法。


  1. [root@localhost ~]# sed 'y/1245/ABCD/' Sed.txt

  2. this is line A, this is First line

  3. this is line B, the Second line, Empty line followed

  4. this is line C, this is Third line

  5. this is line D, this is Fifth line