I am trying to find a file and then edit the text within these files. This is what I have so far, but sadly I'm not that well versed. Help please?

grep -rl "wrongtext" ~/Library/Calendars



sed -i '' 's/wrongtext/righttext/g’

Any ideas?

closed as unclear what you're asking by G-Man, hildred, X Tian, don_crissti, Archemar Oct 18 '15 at 9:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I've edited your question to make it more readable, but your question is not clear to me, please describe the problem in more details. – jimmij Jul 24 '15 at 12:20
  • You can just put the folder after the sed as it accepts multiple files and won't change anything in the ones without wrongtext. sed -i '' 's/wrongtext/righttext/g’ ~/Library/Calendars/* – 123 Jul 24 '15 at 13:25
  • Calendar Cache is a sqlite database. You need to exclude this file. It may also have a backup file in this location. You seem to looking to change Info.plist then try grep -rlZ "wrongtext" ~/Library/Calendars/*/Info.plist – fd0 Jul 24 '15 at 13:42

That should do it:

grep -rlZ "wrongtext" ~/Library/Calendars | xargs -0 sed -i '' 's/wrongtext/righttext/g'

I added the -Z parameter to grep to add a zero byte instead of a newline after every filename. So the command works also with strange filenames. xargs then reads the input delimited by the zero byte with -0 and calls the sed command.

  • Add '' after the -i option or OS X's sed will barf and not execute. – fd0 Jul 24 '15 at 12:25
  • Thanks a lot. Defiantly getting somewhere. However I get this now: OutputOutputOutputOutputOutput OutputOutputOutputOutputOutput OutputOutputOutputOutputOutpu : No such file or directory – user2720970 Jul 24 '15 at 12:43
  • @user2720970 Sry, I had a strange character in the command, try now – chaos Jul 24 '15 at 13:24

Figured it out. It does not like the -O

grep -rlZ "wrongtext" ~/Library/Calendars | xargs sed -i '' 's/wrongtext/righttext/g'

  • you really need '' after sed -i ? I don't have osx at hand. – Archemar Jul 24 '15 at 13:14
  • Yes, you really do... – user2720970 Jul 24 '15 at 13:25
  • it is a -0 not -O – 123 Jul 24 '15 at 13:26
  • Yes, its a numerical 0 – user2720970 Jul 24 '15 at 13:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.