[nSLUG] Find and replace command

Monte Stevens montestevens at eastlink.ca
Sat Oct 4 07:41:26 ADT 2014


Trina Conrad <trina.hanson79 at gmail.com> writes:

> One more question.  When I run the following command:
>
> find -iname '*.html' -print -exec sed -i 's/<link href="../CSS/main.css" rel=
> "stylesheet" type="text/css">/<link href="../../Files/main.css" rel=
> "stylesheet" type="text/css">/' {} \;
>
> I receive the following error:
>
> sed: -e expression #1, char 23: unknown option to `s'
>
> I am not sure why I am getting the error as I have run this command before
> without any errors.

When I count to 23 after `sed' I find myself near to a `/'.

Replace the substitution delimiter `/' characters with another
character, such as `}', i.e., `s}<link href'.

Or, if you like picket fences: escape each not-delimiter `/' (and some
other characters) with a `\', i.e., `..\/CSS\/main\.css'.

  Monte 

>
> Trina
>
> On Thu, Oct 2, 2014 at 11:46 PM, Oliver Doepner <odoepner at gmail.com> wrote:
>
>     I use Windows 7 for a couple of things:
>     - Watch Flash stuff on sites that don't work on the discontinued flash
>     player for linux
>     - Kindle reader to download amazon purchased ebooks (to convert them to
>     epub using calibre)
>     - Use phonerlite to make sipgate phone calls
>     - Generally use my builtin mic (can't get it work on Wheezy)
>     - Fill out Adobe PDF forms that Evince cannot handle
>     - Run the odd Windows only program
>     - Remote desktop into work VMs (via a crappy SSL VPN that only works in
>     IE)
>      
>    
>     On Thu, Oct 2, 2014 at 11:22 PM, Adam MacKinnon <adam at sogo.ca> wrote:
>    
>         Instead of specifying the file mask, you can specify a command
>         (recursive grep should work):   
>         $ perl -pi -e 's/<body background=.*?>/<body>/' `grep -irl "<body
>         background=" *`
>        
>         On Thu, Oct 2, 2014 at 10:39 PM, Trina Conrad <
>         trina.hanson79 at gmail.com> wrote:
>        
>             Hello Oliver,
>            
>             You are correct in your assumptions.  I ran your suggestion and it
>             worked like a charm.  Thank you so very much. :)
>            
>             Trina
>            
>             On Thu, Oct 2, 2014 at 10:36 PM, Oliver Doepner <
>             odoepner at gmail.com> wrote:
>            
>                 Assuming you have only one opening body tag in your html files
>                 and you want to get rid of all the body tag attributes and
>                 your html files all have .html extension :
>                
>                 find -iname '*.html' -print -exec sed -i 's/<body[^>]*>/<body>
>                 /' {} \;
>                
>                 The -print is so that you see the paths of the files being
>                 processed.
>                
>                 _______________________________________________
>                 nSLUG mailing list
>                 nSLUG at nslug.ns.ca
>                 http://nslug.ns.ca/mailman/listinfo/nslug
>
>             _______________________________________________
>             nSLUG mailing list
>             nSLUG at nslug.ns.ca
>             http://nslug.ns.ca/mailman/listinfo/nslug
>
>         --
>         Thanks
>        
>         -Adam
>        
>         _______________________________________________
>         nSLUG mailing list
>         nSLUG at nslug.ns.ca
>         http://nslug.ns.ca/mailman/listinfo/nslug
>
>     --
>     Oliver Doepner
>     http://doepner.net/
>    
>     _______________________________________________
>     nSLUG mailing list
>     nSLUG at nslug.ns.ca
>     http://nslug.ns.ca/mailman/listinfo/nslug
>
> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug


More information about the nSLUG mailing list