Replace text in file with SED

Joao Cunha

I am using git for a rails project and I have in an old committed file the following line: user_name: 'ENV[GMAIL_SMTP_USER]',

I'm trying to replace this line of all the old commits so I can take off the quotes(') and replace them inside the brackets: user_name: ENV['GMAIL_SMTP_USER'],. I am using sed and --tree-filter to accomplish it. Like the following:

git filter-branch --tree-filter "sed -i .bkp s/'ENV[GMAIL_SMTP_USER]'/ENV['GMAIL_SMTP_USER']/g config/environments/development.rb" -f

This command runs fine without errors, but it does not take out the quotes. Also, I can say that the command really works for replacing, since before that, I've successfully used to update user_name: 'myGmailUserName' to user_name: 'ENV[GMAIL_SMTP_USER]'

The problem is only with removing the quotes. What is missing?

Thanks in advance.

Joao Cunha

As Cyrus suggested, I had a problem with escaping, but it was with the quote itself. And also, I don't know why, even with the escaping, it did not work with the repository I was working with, which was a cloned repository (backup).

So, I created a new clone repository and run the following escaping the quotes:

git filter-branch --tree-filter "sed -i.bkp s/\'ENV[GMAIL_SMTP_USER]\'/ENV[\'GMAIL_SMTP_USER\']/g config/environments/development.rb" -f

Does anybody has a better answer? Maybe explaining why it didn't work in the first clone repository...

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

sed won't replace text

分類Dev

Sed replace specific line in file

分類Dev

Sed replace specific line in file

分類Dev

sed command - Replace string in file

分類Dev

sed to replace the middle text of a given string

分類Dev

Sed replace blocks of text from 2 files

分類Dev

sed command not updating text file

分類Dev

How to replace values in a file using sed

分類Dev

Insert File Path Variable into Sed Search/Replace

分類Dev

How to replace a xml file line using sed

分類Dev

using Sed to find and replace a string inside a file

分類Dev

Search replace in XML file with sed or awk

分類Dev

Replace Timestamp in Written Text File

分類Dev

Duplicate and replace a pattern in a text file

分類Dev

sed replace 1 line in file with all lines in file

分類Dev

Using sed to extract strings from a text file

分類Dev

Moving matching lines in a text file using sed

分類Dev

Replacing text in a file using sed with an environment variable

分類Dev

Replace text (e.g. with sed) between strings

分類Dev

Replace line in text file with line from other text file

分類Dev

How to replace an email in a (PHP) file from the command line without sed?

分類Dev

How to do replace using sed only in one section of file

分類Dev

How to use variable in sed command to replace a property value in a property file

分類Dev

Find and replace a character in xml file using sed command is not working

分類Dev

Replace words in an unstructured text file using a for loop

分類Dev

Replace text at specific line number with file name

分類Dev

Cygwin replace all instances of a character in a text file

分類Dev

Read file, search text and replace all the line

分類Dev

Replace text on header and footer of Excel file

Related 関連記事

  1. 1

    sed won't replace text

  2. 2

    Sed replace specific line in file

  3. 3

    Sed replace specific line in file

  4. 4

    sed command - Replace string in file

  5. 5

    sed to replace the middle text of a given string

  6. 6

    Sed replace blocks of text from 2 files

  7. 7

    sed command not updating text file

  8. 8

    How to replace values in a file using sed

  9. 9

    Insert File Path Variable into Sed Search/Replace

  10. 10

    How to replace a xml file line using sed

  11. 11

    using Sed to find and replace a string inside a file

  12. 12

    Search replace in XML file with sed or awk

  13. 13

    Replace Timestamp in Written Text File

  14. 14

    Duplicate and replace a pattern in a text file

  15. 15

    sed replace 1 line in file with all lines in file

  16. 16

    Using sed to extract strings from a text file

  17. 17

    Moving matching lines in a text file using sed

  18. 18

    Replacing text in a file using sed with an environment variable

  19. 19

    Replace text (e.g. with sed) between strings

  20. 20

    Replace line in text file with line from other text file

  21. 21

    How to replace an email in a (PHP) file from the command line without sed?

  22. 22

    How to do replace using sed only in one section of file

  23. 23

    How to use variable in sed command to replace a property value in a property file

  24. 24

    Find and replace a character in xml file using sed command is not working

  25. 25

    Replace words in an unstructured text file using a for loop

  26. 26

    Replace text at specific line number with file name

  27. 27

    Cygwin replace all instances of a character in a text file

  28. 28

    Read file, search text and replace all the line

  29. 29

    Replace text on header and footer of Excel file

ホットタグ

アーカイブ