5

I want to implement the following command recursively

sed -i 's/href=\"1\//href=\"\/1\//g' ./*

so that it replaces all href="1 with href="/1 in all sub-directories. Is there a flag I can add to this command to achieve the results I want?

John
  • 7,153
  • 22
  • 61
  • 86

2 Answers2

13
find . -type f -print0 | xargs -0 sed -i 's/href=\"1\//href=\"\/1\//g'
James
  • 7,553
  • 2
  • 24
  • 33
topdog
  • 3,490
  • 16
  • 13
  • It should be -0 - it matches up with -print0 in the find - edited the post. – James Aug 20 '10 at 16:46
  • I find that `find . -type f | xargs sed -i 's/href=\"1\//href=\"\/1\//g'` can produce the same results. Will there be pitfalls to this approach? – John Dec 07 '19 at 16:54
1

Per https://stackoverflow.com/a/5130044/833771, if the target directory is a Git or SVN root, you should use: find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i 's/href=\"1\//href=\"\/1\//g'

Pr0methean
  • 11
  • 2