Skip to content
Home » Linux » 3 Replace-Equivalent Commands on Linux

3 Replace-Equivalent Commands on Linux

Here are several ways to do replacement on Linux:

  1. Output the replacing result to the same file by sed with option -i
  2. [oracle@test ~]$ sed -i 's/Alex Wu/Steven Li/g' temp.txt

    Output the replacing result to another file by sed without option -i.

    [oracle@test ~]$ sed 's/Alex Wu/Steven Li/g' temp.txt > temp1.txt
  3. Another substitution method is to use the command tr
  4. [oracle@test ~]$ cat temp.txt | tr -s 'r' 'n' > temp1.txt
  5. Or, you can do replacement within vi
  6. [oracle@test ~]$ vi temp.txt
    ...
    :%s/Good/Bad/g

    This means that you want to substitute all "Good" string with "Bad" string globally in this whole document.

Leave a Reply

Your email address will not be published. Required fields are marked *