Robert
Robert

Reputation: 1646

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.

Upvotes: 6

Views: 2338

Answers (1)

Kent
Kent

Reputation: 195219

xargs is the magic you are looking for:

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

Upvotes: 15

Related Questions