Мне дан этот абзац:
*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
Любая помощь приветствуется.
Да, я пытался изменить порядок команд, но он все равно удаляет его. @ВикторСтрибижев
@OldLettuce Если изменение порядка не сработало, вам действительно нужно четко и явно показать вашу точную команду sed.
@John1024 John1024 Все мои команды sed указаны в описании выше. Они находятся в файле сценария и вызываются из другого сценария с помощью команд sed -r -f имя_файла. Я пытался поставить s/%[^%]*% перед s/[0-9]{3}-[0-9]{2}-[0-9]{4}/%%%-%%/%%%%/, но он все равно удаляет символы 2%.
@OldLettuce Не заставляйте нас гадать, как выглядит файл сценария. Поместите файл сценария в свой вопрос. (Если длинное, то, в соответствии с минимальный воспроизводимый пример, удалите все части, которые не нужны для демонстрации проблемы.)
@ John1024 Извините за это. Совершенно новый здесь. Я добавил в свой файл сценария сейчас.





Пытаться:
$ 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.
Можно ли изменить порядок команд?