gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:36 26 4
gpt4 key购买 nike

给我这一段:

*类型转换和角色
* Bob Denver 是 Gilligan,无能且容易出事故的大副
(被“托运人”亲切地称为“小伙伴”)的 SS 米诺号。丹佛并不是让吉利根上场的首选; 1963 年 2 月 11 日, Actor 杰瑞·范·戴克(Jerry Van Dyke,电话 210-222-3333)接到了这个角色的邀请,但他拒绝了,认为该剧永远不会成功。相反,他选择在《我的汽车妈妈》中担任主角,该影片于次年首映,并在一个赛季后被取消。制片人将目光投向了 Bob Denver,他曾在 The Many Loves of Dobie Gillis 中扮演 Maynard G. Krebs, ss #111-22-3333,愚蠢但可爱的垮掉的一代。该剧的每一集都没有具体说明吉利根的全名,也没有明确指出“吉利根”是角色的名字还是姓氏。在 DVD 合集中,舍伍德·施瓦茨表示他更喜欢角色的全名“%Willy Gilligan%”。

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

这是我的其他 sed 命令,以防它可能会干扰其他东西:s+([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})+\3-\2-\1+ g 转换日期格式

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

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

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* 注意 *\n

非常感谢任何帮助。

最佳答案

尝试:

$ 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

这会产生输出:

$ 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.

关于regex - 使用sed删除特定字符之间的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54856250/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com