How to replace a with @, o with 0… in a word list and remove the unchanged words from output

  • A+
Category:Languages

What is the code to replace a with @, o with 0, s with $ and i with 1 in a word list in Linux, filtering off unchanged lines?

Example:

Input

apple pig cut c@t 

Output

@pp1e p1g 

Note that cut and c@t were not in the output since no changes were expected from them.

 


With sed:

sed '/[aosi]/!d;y/aosi/@0$1/' infile 

The first command removes any line that contains none of the characters a, o, s or i. The second command the translates aosi to @0$1. Output (ignoring blank lines):

$ sed '/[aosi]/!d;y/aosi/@0$1/' infile @pple p1g 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: