Find and replace text within a file using commands

Jon Doe

How can I find and replace specific words in a text file using command line?

cscarney
sed -i 's/original/new/g' file.txt

Explanation:

  • sed = Stream EDitor
  • -i = in-place (i.e. save back to the original file)
  • The command string:

    • s = the substitute command
    • original = a regular expression describing the word to replace (or just the word itself)
    • new = the text to replace it with
    • g = global (i.e. replace all and not just the first occurrence)
  • file.txt = the file name

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find and replace text within a file using commands

From Dev

Find and replace text within a file on OSX/bash

From Dev

Find and replace words in a text file using java

From Dev

Using sed to replace text within a java properties file

From Dev

how to find the column number in a text file using unix commands

From Dev

Batch File to Find and Replace in text file using whole word only?

From Dev

how to find text within a file using grep it hangs in terminal

From Dev

Find and replace text in a file between range of lines using sed

From Dev

Find and Replace Text in file if exists / Append if not exists using Perl

From Dev

Find/Replace special characters in text file using Bash script

From Dev

How to Find & Replace Strings with Incrementing Variables in a Text File Using Awk

From Dev

Find & Replace in multiple text files within a folder

From Dev

Sublime Text: Find-and-replace within selection

From Dev

Find and replace text within multiple files

From Dev

Find and replace text file Matlab

From Dev

Find and replace text file Matlab

From Dev

Using sed to find-and-replace in a text file using strings from another text file

From Dev

MS Word Find and Replace text within all docs in a folder using VBA

From Dev

Python 2.7 - find and replace from text file, using dictionary, to new text file

From Dev

find and replace text in a text file (including spaces!)

From Dev

VBA Find and Replace Text in a Text File

From Dev

Using Grunt to Replace Text in a File

From Dev

Using Grunt to Replace Text in a File

From Dev

How to find strings within a text file in JAVA

From Dev

Search and replace within a file using PCRE in C

From Dev

Replace text within a text file with Windows command line

From Dev

How to find and replace multiple lines in text file?

From Dev

Find and replace a string in a text file in Perl

From Dev

Find and replace words in text file recursively

Related Related

  1. 1

    Find and replace text within a file using commands

  2. 2

    Find and replace text within a file on OSX/bash

  3. 3

    Find and replace words in a text file using java

  4. 4

    Using sed to replace text within a java properties file

  5. 5

    how to find the column number in a text file using unix commands

  6. 6

    Batch File to Find and Replace in text file using whole word only?

  7. 7

    how to find text within a file using grep it hangs in terminal

  8. 8

    Find and replace text in a file between range of lines using sed

  9. 9

    Find and Replace Text in file if exists / Append if not exists using Perl

  10. 10

    Find/Replace special characters in text file using Bash script

  11. 11

    How to Find & Replace Strings with Incrementing Variables in a Text File Using Awk

  12. 12

    Find & Replace in multiple text files within a folder

  13. 13

    Sublime Text: Find-and-replace within selection

  14. 14

    Find and replace text within multiple files

  15. 15

    Find and replace text file Matlab

  16. 16

    Find and replace text file Matlab

  17. 17

    Using sed to find-and-replace in a text file using strings from another text file

  18. 18

    MS Word Find and Replace text within all docs in a folder using VBA

  19. 19

    Python 2.7 - find and replace from text file, using dictionary, to new text file

  20. 20

    find and replace text in a text file (including spaces!)

  21. 21

    VBA Find and Replace Text in a Text File

  22. 22

    Using Grunt to Replace Text in a File

  23. 23

    Using Grunt to Replace Text in a File

  24. 24

    How to find strings within a text file in JAVA

  25. 25

    Search and replace within a file using PCRE in C

  26. 26

    Replace text within a text file with Windows command line

  27. 27

    How to find and replace multiple lines in text file?

  28. 28

    Find and replace a string in a text file in Perl

  29. 29

    Find and replace words in text file recursively

HotTag

Archive