How to Replace a String Command Line

Sed is a command line tool that is installed by default on Unix and Linux operating systems and available for download for the Windows operating system. Sed is used to filter text which means text is provided as input, and the utility performs the operations required and the modified text is provided as output. It is typically used for pattern matching or string substitution. Sed can use literal strings or regular expressions in the pattern matching or substitution.

Things You'll Need

  • Sed
Show More

Instructions

    • 1

      Open a terminal window. A terminal window will provide a command prompt where you will type the following commands.

    • 2

      Navigate to the directory where your files that you want to edit are located.

    • 3

      Type "sed 's/search/replace/g' *.txt" to replace all the instances of the string "search" with the string "replace" in "file.txt."

    • 4

      Open the files in a text editor to check that the string has been replaced.

    • 5

      Type "exit" to close the terminal session.

Tips & Warnings

  • A version of sed is available for the Windows operating system (see Resources)

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured