Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the Unix tr command on a file in max os X

Tags:

unix

macos

tr

In Mac OS X Terminal, I can't seem to use the 'tr' command on a file.

For example, I have a text file called 'z.txt' on my desktop. I would like to substitute every letter 'a' into the letter 'e'.

tr "a" "e" z.txt

returns the following message:

usage: tr [-Ccsu] string1 string2
       tr [-Ccu] -d string1
       tr [-Ccu] -s string1
       tr [-Ccu] -ds string1 string2

Conversely, this works just fine:

sed "s_a_e_g" z.txt

What syntax or quoting should I use to make the 'tr' approach work?

like image 224
user3781201 Avatar asked Feb 01 '26 17:02

user3781201


1 Answers

You can direct the file into tr.

tr "a" "e" < z.txt
like image 75
Praxeolitic Avatar answered Feb 03 '26 06:02

Praxeolitic