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

Re: Deleting some regexp/simple expression from lots of files in a secure way



On 05/14/2010 10:37 AM, Boyd Stephen Smith Jr. wrote:
> On Friday 14 May 2010 12:04:42 Merciadri Luca wrote:
>> I have many text files (actually .tex files) which contain some
>> sequence or regexp (it depends on the files) that I would like to
>> remove. Is there a commandline/GUI for doing this massive edit?
> 
> (sed -i -e "s/$regexp//" "$file") for a single file.  (GNU sed only.)
> 

If you're not comfortable with making the change in place (meaning
losing the original, in case you got something wrong in the script),
just add a "SUFFIX" to the -i option, as in '-i.bak', and sed will make
a backup copy, using the suffix as the extension appended to the file name.

> (find $dir -type f -exec sed -i -e "s/$regexp//" {} \;) for all files in a 
> directory.

-- 
Bob McGowan


Reply to: