-2
  1. I have a directory with multiple subdirectories, wherein each contain multiple files.
  2. Many files contain the sentence "these are all my pencils.".
  3. I want to replace all occurrences of that sentence with "my pens are the following, ok."

How do I do that effectively from within the parent directory in question?

Examples of my attempts:

1] find <mydir> -type f -exec sed -i 's/these are all my pencils/my pens are the following, ok/g' {} +

2] find . -type f -not -path '*/\.*' -exec sed -i 's/these are all my pencils/my pens are the following, ok/g' {} +

I don't know why this reference isn't working.

None of the attempts effected any changes. Attempt 1] complained about "command c expects \ followed by text". Attempt 2] complained against "invalid command code .". I tried many of the others to no avail as well. (I can't list all of them.)

Mwen Rele
  • 93
  • 1
  • 8
  • well, I wasn't expecting a negative vote without explanation. Perhaps StackOverflow should require explanations for negative votes, that way I know what I did wrong and not waste people's time in the future? – Mwen Rele Jun 10 '20 at 17:12
  • I'll guess that the downvote is because of the magic phrase, "isn't working". :) If you updated your question to include exactly what you typed, and what (if anything) happened -- like an error message, you might get a better response. – Phillip Mills Jun 10 '20 at 17:25
  • Not the downvoter, but you say you don't know why that reference isn't working. First, that reference contains 35 different answers, so it's not clear what you tried. Second, just saying it isn't working isn't very helpful. How is it not working? What is happening? Is it showing any errors? Changing some files but not others? Doing nothing at all? And third, some people on SO just downvote, don't worry too much about it. Wait for constructive feedback and improve your question :-) – jas Jun 10 '20 at 17:27
  • 2
    Not the downvoter either but - no sample input, no expected output, no attempt to solve the problem, no statement of issues you've encountered trying to solve the problem. It's just not an appropriate question for this forum, see [ask] and you may as well delete this to stop it accumulating down/close votes while you figure if you have a question for this forum or not and, if so, how to create a [mcve] to ask it. – Ed Morton Jun 10 '20 at 17:59
  • I have updated the question – Mwen Rele Jun 10 '20 at 19:07

1 Answers1

0

You're on MacOS - the default sed there requires a backup file name after -i (unlike GNU sed) so if that's what you're using then that's probably your problem. Check the man page.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185