0

I tried the following but not adding '' this example

I want to replace FILENAME_LOGIN to 'login.php'

Tried this:

grep -r "login.php" -l | tr '\n' ' ' | xargs sed -i 's/"login.php"/'login.php'/g' 

However, it gives me login.php not 'login.php'

Thanks

2
  • Untested, but try to escape the single quotes: xargs sed -i 's/"login.php"/\'login.php\'/g' - or double-escape: xargs sed -i 's/"login.php"/\\'login.php\\'/g' Commented Sep 4, 2017 at 14:13
  • You can't include single quotes in a single-quote delimited script, no matter how many times you try to escape them. Commented Sep 4, 2017 at 16:07

3 Answers 3

1

You only need sed for this:

sed -i -e "s/FILENAME_LOGIN/'login.php'/g" /your/file 
Sign up to request clarification or add additional context in comments.

Comments

0

I figured it out:

find ./ -type f -exec sed -i -e 's/FILENAME_LOGIN/'login.php'/g' {} \; 

2 Comments

Yes, this will search in files in any subdirectory, nice! :)
it won't add single quotes around the text though.
0
find ./ -type f -exec sed -i -e 's/FILENAME_LOGIN/'\''login.php'\''/g' {} \; 

1 Comment

Thank you for this code snippet, which may provide some immediate help. A proper explanation would greatly improve its educational value by showing why this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Even something as simple as "You forgot to quote the ' characters" would be a great improvement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.