首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用sed删除特定字符之间的字符

使用sed删除特定字符之间的字符
EN

Stack Overflow用户
提问于 2019-02-25 04:31:24
回答 1查看 50关注 0票数 1

我得到了这段话:

*Cast and characters * Bob Denver is Gilligan, the inept, accident-prone First Mate (affectionately known as "Little Buddy" by "the Shipper") of the SS Minnow. Denver was not the first choice to play Gilligan; actor Jerry Van Dyke, phone 210-222-3333, was offered the role on 2/11/1963, but he turned it down, believing that the show would never be successful. He chose instead to play the lead in My Mother the Car, which premiered the following year and was cancelled after one season. The producers looked to Bob Denver, the actor who had played Maynard G. Krebs, ss #111-22-3333, the goofy but lovable beatnik in The Many Loves of Dobie Gillis. None of the show's episodes ever specified Gilligan's full name or clearly indicated whether "Gilligan" was the character's first name or his last. In the DVD collection, Sherwood Schwartz states that he preferred the full name of "%Willy Gilligan%" for the character.

我的目标是使用sed将"%Willy Gillgan%"转换为""。我尝试过s/%[^%]*%//,但它也会干扰另一个将#111-22-3333更改为#%%%-%%-%%%%的sed命令s/[0-9]{3}-[0-9]{2}-[0-9]{4}/%%%-%%/%%%%/。它错误地删除了2%的变成#%-%%-%%%%

下面是我的其他sed命令,以防它与其他内容发生冲突:s+([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})+\3-\2-\1+g转换日期格式

/[*]\s/i\ \n* ATTENTION *\n在段落中的任意位置遇到"*“时,它会添加”*注意*“行和换行符。

这是我的脚本文件的样子:

s/[0-9]{3}-[0-9]{2}-[0-9]{4}/%%%-%%/%%%%/

s+([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})+\3-\2-\1+g

s/%[^%]*%//

/[*]\s/i\ \n* ATTENTION *\n

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-25 05:45:51

尝试:

代码语言:javascript
运行
复制
$ cat script.sed
s/%[^%]*%//g
s/[0-9]{3}-[0-9]{2}-[0-9]{4}/%%%-%%-%%%%/g
s+([0-9]{1,2})[/-]([0-9]{1,2})[/-]([0-9]{4})+\3-\2-\1+g
/[*]\s/i\
\n* ATTENTION *\n

这将生成以下输出:

代码语言:javascript
运行
复制
$ sed -Ef script.sed text
*Cast and characters

* ATTENTION *

* Bob Denver is Gilligan, the inept, accident-prone First Mate
(affectionately known as "Little Buddy" by "the Shipper") of the SS Minnow. Denver was not the first choice to play Gilligan; actor Jerry Van Dyke, phone 210-222-3333, was offered the role on 1963-11-2, but he turned it down, believing that the show would never be successful. He chose instead to play the lead in My Mother the Car, which premiered the following year and was cancelled after one season. The producers looked to Bob Denver, the actor who had played Maynard G. Krebs, ss #%%%-%%-%%%%, the goofy but lovable beatnik in The Many Loves of Dobie Gillis. None of the show's episodes ever specified Gilligan's full name or clearly indicated whether "Gilligan" was the character's first name or his last. In the DVD collection, Sherwood Schwartz states that he preferred the full name of "" for the character.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54856250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档