Search code examples
sedag

Find and replace text in files with the silver searcher and sed


Heck I just can't remember ... I recently had a cool way to use ag with sed to do find and replace. The gist was simple, something like:

ag foo -l |  ... magic here ...   sed 's/foo/bar/g'

That doesn't work, but you might just know what does. Thanks!

PS. Three cheers for the Silver Searcher.


Solution

  • xargs is the magic you are looking for:

    ag -l 'foo'|xargs sed -i 's/foo/abcd/g'