[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: replace string



> From: "Mad Unix" <madunix gmail com>
> 
> i need your feedback about this command, it should find a
> string in
> multiple html files in a directory and replace it with a
> different
> string...
> 
> find /dir -name "*.html" -exec sed i 's/"old"/"new"/g' {} \;
> 
> Thx.

Even if you get your sed command right, that won't do in-place replacement, because if you use sed, the result has to be saved to a different file and you mv that file to overwrite your original file.

Perl's in-place edit helps in your case:

find /dir -name "*.html" -exec perl -pi -e 's/old/new/g' {} \;

Yong Huang


      



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]