Удалить символы между конкретными символами, используя sed - PullRequest
0 голосов
/ 24 февраля 2019

Мне дан этот параграф:

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

Моя цель - сделать "%Willy Gillgan%" в "", используя sed.Я пробовал 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 добавляет* ВНИМАНИЕ * и символ новой строки, когда он встречает "*" в любом месте абзаца.

Вот как выглядит мой файл скрипта:

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

Любая помощь с благодарностью.

1 Ответ

0 голосов
/ 25 февраля 2019

Попробуйте:

$ 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.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...