我要翻译的内容:如何删除包含有特殊字符分隔块的文本部分?

huangapple go评论62阅读模式
英文:

How can I remove part of a text containing a delimited block of special characters?

问题

我有一段100个字符串的文本,我必须删除每个字符串的一部分,即删除以`-it`开头并且长度为10个字符的部分,然后保留剩余部分。

这是要处理的字符串:

```none
<a href="lyudmila<sup>-it48ceer3</sup>/index.html" target="_self" ref="title">< redincontri >**

<a href="cerco-una-donna-scopo-matrimonio-it9734n7n/index.html" target="_self" ref="title">< redincontri >
<a href="serio-carino-alto-188-m-ironico-per-bella-donna-al-massimo-di-48-anni-si-whatsapp<sup>-it7xda7k8</sup>/index.html

要删除的字符序列以-it开头,长度为10个字符。

我尝试过使用sed和grep,但没有得到结果。


<details>
<summary>英文:</summary>

I have a block of 100 strings of text and I must delete part of every string, i.e., delete 10 characters starting with `-it`, and leave the rest.

This is the string:

```none
&lt;a href=&quot;lyudmila&lt;sup&gt;-it48ceer3&lt;/sup&gt;/index.html&quot; target=&quot;_self&quot; ref=&quot;title&quot;&gt;&lt; redincontri &gt;**

&lt;a href=&quot;cerco-una-donna-scopo-matrimonio-it9734n7n/index.html&quot; target=&quot;_self&quot; ref=&quot;title&quot;&gt;&lt; redincontri &gt;
&lt;a href=&quot;serio-carino-alto-188-m-ironico-per-bella-donna-al-massimo-di-48-anni-si-whatsapp&lt;sup&gt;-it7xda7k8&lt;/sup&gt;/index.html

The character sequences to remove start in -it and are 10 characters long.

I have tried with sed and with grep, but with no result.

答案1

得分: 1

尝试使用sed命令,使用-E选项启用扩展正则表达式:

sed -E 's/-it\w{7}//g' input.txt > output.txt
英文:

Try it like so with sed using the -E option to enable extended regular expressions:

sed -E &#39;s/-it\w{7}//g&#39; input.txt &gt; output.txt

huangapple
  • 本文由 发表于 2023年6月22日 07:58:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76527831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定