English 中文(简体)
如何用 s子删除html元件?
原标题:How to delete html meta tag using sed?
  • 时间:2011-11-03 12:53:44
  •  标签:
  • html
  • sed

Ive编造了许多指数.html,并 h。 现在,我想要删除另外2个 with子。

the:

<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->

i 认为这是一种办法,可以把所有指数的html复发。

cd /home/user/websites
grep -lr -e  index  *.html | xargs sed -i  s/<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
//g 

it doesent work please help me thanks

最佳回答

为此:

grep -lr -e  index  *.html | xargs sed -i .bak -e  s#<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->##g 

但是,如果你想要修改的文件contain<>/strong>index,这只会奏效。 如果您希望修改所有<代码>index.html,现名录及其子标题下的文档均使用:

find . -name  index.html  | xargs sed -i .bak -e  s#<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->##g 

Either way, the important thing was to replace / with # in the sed s s command. This command allows you to use almost any separator as long as you re consistent (i.e. all three separators are the same character). You should pick the separator that does not appear in your expression or you have to escape it there.

Also note that I modified flags to sed. From sed man page:

 -i extension
         Edit files in-place, saving backups with the specified extension.  If a zero-length extension is given, no backup will be saved.  It is not recom-
         mended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situations where disk space is
         exhausted, etc.

 -e command
         Append the editing commands specified by the command argument to the list of commands.

This means that my commands will save every file as a backup before modifying and append .bak to the backup file s name. If you don t want the backups pass the zero-length extension like this: -i .

普通表达方式不够有力,不足以达到超文本。 在这里,它只是因为你拥有一个固定的级的特性,以取代刚刚变成“超”的特性。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!