?

Log in

No account? Create an account
Overloading the Machine -- Day [entries|friends|calendar]
johnsu01

[ website | wjsullivan.net ]
[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

sed one-liner to replace based on grep results [27 Oct 2004|12:20am]

I used this to replace a mistake in the address at work that was made in dozens of files. It replaced every occurrence of " 9 Temple Place" with " 59 Temple Place", recursively.

sed -i 's/\ 9\ Temple\ Place/\ 59\ Temple\ Place/g' $(grep -lr " 9 Temple Place" ./*)

If you wanted to play it safe and make a backup of all the files that were changed, you would replace "-i" with "-i.bak" or whatever suffix you like to use for backups.

post comment

navigation
[ viewing | October 27th, 2004 ]
[ go | previous day|next day ]