Я пытаюсь узнать о sed, grep и awk, и я столкнулся со следующей проблемой: у меня есть следующий журнал после использования sed, чтобы получить все строки между двумя шаблонами (START и КОНЕЦ):
START
tag: text info text text info text
text info texttext info text
text info texttext info text
text info texttext info text
other_tag: text info text text info text
text info text text info text text info text
text info text text info text text info text
END
START
tag: text info text text info text
text info text text info text
text info text text info text
other_tag: text info text text info text
text info text text info text text info text
text info text text info text text info text
END
Я хотел бы объединить все строки с их родителями, удалив начальную [табуляцию], например:
START
tag: text info text text info text text info text text info text text info text text info text text info text text info text
other_tag: text info text text info text text info text text info text text info text text info text text info text text info text
END
START
tag: text info text text info text text info text text info text text info text text info text
other_tag: text info text text info text text info text text info text text info text text info text text info text text info text
END
Кто-нибудь может мне помочь? Спасибо!
Возможно, вам следует продолжать использовать sed . Использование N может добавить следующую строку ввода в пространство шаблона, после чего вы можете сопоставить \n между двумя строками.
См.:
sed ':a; N; $!b a; s/\n\s\{1,\}/ /g'