英文:
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
<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
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 's/-it\w{7}//g' input.txt > output.txt
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论