[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



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bob McGowan <bob_mcgowan@symantec.com> writes:

> On 05/14/2010 10:52 AM, Merciadri Luca wrote:
>> "Boyd Stephen Smith Jr." <bss@iguanasuicide.net> writes:
>> 
> ---removed on purpose---
>>> (find $dir -type f -exec sed -i -e "s/$regexp//" {} \;) for all files in a 
>>> directory.
>> Thanks both. (@Andrei: it was in the content of the file, sorry not to
>> have specified it before.)
>> 
>> I am using the second command. The problem is that, for one set of
>> files (that I have selected, no problem for this), I have to use a
>> really simple expression: I need to find all the occurences of
>> `\paragraph{}' and replace them with nothing (i.e. with `'). I know
>> regexps, but replacing `$regexp' with `\paragraph{}' gives error
>> messages. Any idea? Thanks.
>> 
>
> In Boyd's example, you can see 'find' uses '{}' as a place holder, to be
> replaced by each file name as it's found.
>
>>From the 'find' man page:
>
> -exec command ;
>     Execute  command;  true  if 0 status is returned.  All following
>     arguments to find are taken to be arguments to the command until
>     an  argument  consisting of ‘;’ is encountered.  The string ‘{}’
>     is replaced by the current file name being processed  everywhere
>                                          emphasis added:  ^^^^^^^^^^
>     it occurs in the arguments to the command, not just in arguments
>     where it is alone, as in some versions of find. ...
>
> So, you get file names in both places.  Since file names are probably
> relative paths, they will contain added slashes, which confuse sed.
>
> I could not find any reference to how to make '{}' be handled literally
> by find.
>
> You could try using a '.*' or '.?' between the braces in the sed
> expression and see if that stops find from replacing them.  Since they
> both expand to a 'zero or ...', they will match '{}'.  The problem being
> they will also match the longest '{...}' in the line, so all lines would
> have to have no more than one pair.  As I don't do tex, I don't know if
> this can be counted on or not.
>
> sed does have a '-r / --regexp-extended' option, and some 'extended'
> regex engines allow specifying a 'shortest' rather than 'longest' match,
> but I don't have any experience with extended regex in sed, you will
> have to experiment.
Thanks.

- -- 
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- -- 

Do all the good you can, By all the means you can, In all the ways you can, In all the places you can, At all the times you can, To all the people you can, As long as ever you can. (John Wesley)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iEYEARECAAYFAkvtqJ0ACgkQM0LLzLt8MhzLkwCgnOzQ9C/75RCxSXN7HpUXcca+
GBkAn1aMDN2LP79WDmRKEnGFblQkFZfW
=sBL7
-----END PGP SIGNATURE-----


Reply to: